Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Observer Pattern

 
Servo Alvo
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fellows,


According to this Java World´s article, the only one way to implement Observer Pattern is using composite, ie, adding the observer as a member of the subject and vice-versa ??

Thanks in advance!

 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcelo, what do you think about the author's statements? Do you have any opinions about the topic or specific questions?

If you have any questions, please describe the context of the questions so readers can get a better understanding of the question(s).
 
Servo Alvo
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I was a little vague.

Consider this class



and this one:



and finally to this one:





so my question applies to this hyphotetical scenario.


Thanks again.

 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your question?
 
Servo Alvo
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is, that composition (or aggregation some might say) - Observer as Subject member and Subject as Observer member - is the only way to implement the pattern for JEE ?

 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- is the only way to implement the pattern for JEE ?


The pattern itself has nothing to do with the Java Enterprise Edition API's. If you are referring to implementing the pattern with the Java language, then no this is not the only way. This is the most simple way and easy for the novice to understand, but it is not the "only" way.

There are more complex push/pull strategies and other ways to implement the pattern, e.g. using lookup mechanisms, etc.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a skeleton to implement it in Java. java.util.Observable and Observer but they are not very flexible.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic