• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# a matter of hierarchy ?

## Recommended Posts

Hi ppl, The following situation happens to me over n over again. I have an object A that creates objects of class B. Now I have objects of class C that need references to objects B stored in A. What is a good way to pass them around ? Making a ''Getter'' for every reference feels quite awkward. Creating objects B before A and the C''s and then passing them at instantiation of A and C also doesn''t feel right since they shouldn''t be that global. What is a standard approach to this basic problem ? Tnx for any comment Lorenz

##### Share on other sites
There's no standard approach. Well, maybe getters are. But what you *should* do depends highly on the specific problem. There may be some super-elegant solution you just haven't thought about yet but it's impossible to tell without full context. (Note: this is not an invitation to write the problem here, but to perhaps first solve it with getters and refactor it later into a better design if you come up with one)

[edited by - civguy on May 5, 2003 3:46:14 AM]

##### Share on other sites

For my problem I''ll give you some information.

I have a class of type CInterruptHandler which will create objects of CInterrupt passing itself so that the interrupt objects know who their handler is (There might be more than one handler).

The interrupts will be passed to objects that can cause an interrupt. (Mediator pattern would be cool but some objects have more than one interrupt reference). The Interrupt handler doesn''t know and doesn''t need to know about the objects, only to which object it is passed to so that it can take proper actions.

A derived class of the handler would look like:

  class CInterrupt;class CIntHandlerDerived : CInterruptHandler{CIntHandlerDerived();~CIntHandlerDerived();// Some functions// ..// GetterCInterrupt* GetTimerInt();CInterrupt* GetSoundInt();CInterrupt* GetVideoInt();// The interrupt objectsprivate:CInterrupt* pTimerInterrupt; // To be passed to the timer objectCInterrupt* pVideoInterrupt; // To be passed to the video objectCInterrupt* pSoundInterrupt; // To be passed to the sound object}

Can''t help it. I just don''t get along with it. What do you think ?