Sign in to follow this  
wolfram

what design pattern ?

Recommended Posts

wolfram    122
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
Guest Anonymous Poster   
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
wolfram    122
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this