Jump to content
  • Advertisement
Sign in to follow this  
wolfram

what design pattern ?

This topic is 4452 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can't figure out what design patter this is. Does anyone know? class A; class B { public: virtual ~B(); virtual void Update(A* aA)=0; protected: B(); } class A { public: virtual ~A(); virtual void Attach(B* aB); virtual void Detach(B* aB); virtual void Notify(); protected: A(); private List<B*> someB; } void A::Attach(B* aB){ someB.Append(aB); } void A::Detach(B* aB){ someB.Remove(aB); } void A::Notify(){ ListIterator<B*> i(someB); for(i.First();!i.IsDone();i.Next){ i.Currentitem()->Update(this); } }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
search and replace A Observable
search and replace B Observer

class Observable;

class Observer {
public:
virtual ~Observer();
virtual void Observer(Observable* o)=0;
protected:
Observer();
}


class Observable {
public:
virtual ~Observable();
virtual void Attach(Observer* o);
virtual void Detach(Observer* o);
virtual void Notify();
protected:
Observable();
private:
List observers;
}

void Observable::Attach(Observer* o){
observers.Append(o);
}

void Observable::Detach(Observer* o){
observers.Remove(o);
}

void Observable::Notify(){
ListIterator i(observers);
for(i.First();!i.IsDone();i.Next){
i.Currentitem()->Update(this);
}
}

So I'd say it's the Observer pattern :-)

Share this post


Link to post
Share on other sites
Thanks! Its quite difficult to figure it out, i think.
A friend of mine said that I might need it, but he had no name for it.
Anyway, its very nice that someone pays attention to this post! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!