









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A presentation on the observer pattern
Typology: Slides
1 / 17
This page cannot be seen from the preview
Don't miss anything!










(^) Uzama Osaweosemenor Jasiel 19/ (^) Francis King-David Chuks 20/ (^) Worancha Mishael Gebre 19/ (^) Okeowo Olamilekan 19/
OBSERVER DESIGN PATTERN (^) Observer is a behavioral design pattern : These patterns are designed depending on how one class communicates with others. (^) This pattern lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing. (^) Other examples of behavioral patterns include Chain of responsibility Pattern, Command Pattern, Interpreter Pattern among others.
Motivation of the observer pattern(The Context) (^) Inadequate availability of patient information is a major cause for medical errors and affects costs in healthcare. Traditional information integration in healthcare does not solve the problem. (^) An improvement for the information exchange is needed. The goal is to provide better information exchange between institutions.
A simple diagram to show the application of observer pattern in patient care
STRUCTURE (^) 1. The Observable issues events of interest to other objects. These events occur when the observable changes its state or executes some behaviors. The observable contains a observer infrastructure that lets new observers join and current observers leave the list. (^) 2. When a new event happens, the observable goes over the observer list and calls the notification method declared in the observer interface on each observer object. (^) 3. The Observer interface declares the notification interface. In most cases, it consists of a single update method. The method may have parameters that let the observable pass some even details along with the update. (^) 4. Concrete Observers perform some actions in response to notifications issued by the observable. All of these classes must implement the same interface so the observable isn’t coupled to concrete classes.
BASIC ILLUSTRATION OF THE OBSERVER DESIGN PATTERN
CLASS DIAGRAM SHOWING THE APPLICATION OF OBSERVER DESIGN PATTERN
PROS AND CONS (^) Provides a loosely coupled design between objects that interact. Loosely coupled objects are flexible with changing requirements. Here loose coupling means that the interacting objects should have less information about each other. (^) Observer pattern provides this loose coupling as: (^) Subject only knows that observer implement Observer interface. Nothing more. (^) There is no need to modify Subject to add or remove observers. (^) Memory leaks caused by Lapsed listener problem because of explicit register and unregistering of observers. (^) The communication between the observable and observer is synchronous and with an increased load of subscribing and unsubscribing events, the observable object could be bombarded with requests. This could be mitigated by setting up a sleep time for each request.
Relations with Other Patterns (^) Chain of Responsibility , Command , Mediator and Observer address various ways of connecting senders and receivers of requests: (^) Chain of Responsibility passes a request sequentially along a dynamic chain of potential receivers until one of them handles it. (^) Command establishes unidirectional connections between senders and receivers. (^) Mediator eliminates direct connections between senders and receivers, forcing them to communicate indirectly via a mediator object. (^) Observer lets receivers dynamically subscribe to and unsubscribe from receiving requests.