From: Brown J. L <Bro...@Jo...> - 2002-06-17 22:05:05
|
>What if you did an observer pattern? Your object that creates the 5 other >objects can register itself as listeners to those 5 objects. When each of >the 5 objects generates somethings that needs to be added to the queue it >could fire off an event to all listeners. In this case, the listener would >be the object with the queue which would handle the event and add the >object to the queue. Basically what I really need to do is have each of the 5 sub-objects own a handle to their parent class that get's created when they are instantiated - that way I can access the public methods of the parent class. Is that how the observer model works? > >Otherwise, if each subclass has it's OWN queue, just make the queue >protected in the base class and access it directly. > >As you can see, since the base class has the queue, I'm wondering why the >other 5 objects need to derive from the base class The 5 subclasses don't derive from a base class, they are seperate objects contained in a class along with the queue, the super/parent class just creates instances of them. unless each object is >supposed to have its own queue. > >cheers, ----- Ben Scott Research Assistant VRAC bs...@ia... On Mon, 17 Jun 2002, Brown Joshua L wrote: > hello I'm still stuck on the following problem: > > If I have a class that instantiates 5 subclasses and 1 queue, and the 5 > sub-classes are supposed to push and pop elements on the queue, what is a > good model for giving the subclasses access to the queue. > > Do I need to have a constructor for each subclass that allows me to pass in > a queue - because that method really sucks. > > j > > Josh Brown > Undergraduate - Iowa State University > Research Intern - John Deere and Co > > > |