OO design question (please help settle a dispute)

Discussion in 'C' started by Miles123, Aug 18, 2007.

  1. Miles123

    Miles123 New Member

    Joined:
    Aug 18, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    OO design question (please help settle a dispute)
    Please help me settle an argument that has been simmering for almost a week now at my workplace. I'm having a hard time convincing one of our product designers that there is a really basic design smell in our new product, so I thought I would throw this question out to the gurus and code Jedis populating these forums.

    So the overview:

    We have 2 singleton classes - an overall Application class and a MessageRouter class. The routing mechanism is accomplished through the use of Agent classes, this class is a base class from which we subclass multiple concrete Agent types. Agent objects must register with the router in order to be notified of state changes. Also, agent registration with the router will occur in multiple places inside the code - not just within Application.

    On program startup, the original proposed architecture was as follows:

    Proposal A:
    Code:
    Code:
    Application::Initialize()
    {
    AgentSubclass foo = new AgentSublass()
    foo->Initialize()
    }
    
    Agent::Initialize()
    {
    MessageRouter::Instance()->Register(this)
    }
    I personally did not agree with this design, and proposed the following change:
    Proposal B:
    Code:
    Code:
    Application::Initialize()
    {
    AgentSubclass foo = new AgentSublass()
    foo->Initialize(MessageRouter::Instance())
    }
    
    Agent::Initialize(MessageRouter *pRt)
    {
    pRt->Register(this)
    }
    
    So to the world: which proposal is a better one in terms of OO Design and also given the fact that our group is committed to a TDD approach? I won't initially give my reasons for why I proposed B (I don't want to slant the discussion in my favor).

    Thanks for the help.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,376
    Likes Received:
    388
    Trophy Points:
    83
    I don't see anything different in the above 2 solutions apart from the fact that one is passing the Router and the other using the Singleton Class instance. Now as it looks like you have Singleton router and so its object passing is not at all needed ( Unless you have some interface and the Router will not be available directly to the Agent class in future ).

    I would vote for proposal A
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice