Visitar URL original
java-design-pattern/wiki/Observer.md at master · mquan86/java-design-pattern · GitHub
Skip to content

Latest commit

 

History

History
20 lines (13 loc) · 847 Bytes

Observer.md

File metadata and controls

20 lines (13 loc) · 847 Bytes

Observer

Pattern

A one to many relationship between objects to notify them about state change in one object. Usually used in event/listener handling.

Recognized by method notifies state change to another instances.

Example

A document repository application could notify related users and admins about document state change on saving action.

Downside

Could lead to memory leak with reference to observers.

Note

Java provide a convenient built-in Observer pattern with java.util.Observer and java.util.Observable