Just observers knows your target ( Subject ) ? In a relation of One to One ( with direction just observer -> subject , without get back )
I think ( in my opinion ) that the subject had a list of observers and in your update performed the method to notify them..
But seing your implementation , you give the responsability to observers of receive the subject and into constructor of the observer call the subject and run the .registerObserver() method. Why this choice?
Summary: Why the each observer know your subject and not one subject knows your observers ( having a list of them );
Good question Marlysson! I had the same thought when I was reading this chapter. The text doesn’t mention why they chose this design. But they did give another example of the Observer pattern implementation in the JDK, specifically in Swing. And in this example, the Subject constructor take an Observer, and registers it as an observer. So I guess it’s flexile?
I agree. When I was studying these patterns emerged the same doubt. I think there are severals design to implement observer pattern, each one suitable to right problem.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just observers knows your target ( Subject ) ? In a relation of One to One ( with direction just observer -> subject , without get back )
I think ( in my opinion ) that the subject had a list of observers and in your update performed the method to notify them..
But seing your implementation , you give the responsability to observers of receive the subject and into constructor of the observer call the subject and run the .registerObserver() method. Why this choice?
Summary: Why the each observer know your subject and not one subject knows your observers ( having a list of them );
Great article.
Good question Marlysson! I had the same thought when I was reading this chapter. The text doesn’t mention why they chose this design. But they did give another example of the Observer pattern implementation in the JDK, specifically in Swing. And in this example, the Subject constructor take an Observer, and registers it as an observer. So I guess it’s flexile?
I agree. When I was studying these patterns emerged the same doubt. I think there are severals design to implement observer pattern, each one suitable to right problem.