aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Observer Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Observer Pattern" Watch "Observer Pattern" New topic
Author

Observer Pattern

Servo Alvo
Greenhorn

Joined: Jan 13, 2010
Posts: 24
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

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Jan 13, 2010
Posts: 24
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

Joined: Apr 16, 2008
Posts: 2187
What is your question?
Servo Alvo
Greenhorn

Joined: Jan 13, 2010
Posts: 24
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

Joined: Apr 16, 2008
Posts: 2187
- 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

Joined: Apr 20, 2009
Posts: 804
    
    1

There is a skeleton to implement it in Java. java.util.Observable and Observer but they are not very flexible.


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Observer Pattern