The goal of this lab is to use the observer design pattern to solve a real-world problem.
Design patterns are proven solutions to solve recurring design problems to design flexible and reusable object-oriented software; that is, objects that are easier to implement, change, test and reuse. Behavioral patterns deal with the communication between objects and structuring the responsibilities between objects to keep them extensible, flexible and efficient.
The observer design pattern (a.k.a. dependency broadcasting, publish-subscribe pattern) is one of the twenty-three well-known Gang of Four (GoF) design patterns. It is classified under the category of behavioral patterns.
The observer design pattern allows us to implement a subscription service in which an object called the subject maintains a list of dependent objects called observers. The subject notifies the observers of a change to the subject’s state and broadcasts the change to them by calling the observers’ methods.
In the observer pattern, a subject maintains a list of observers and notifies them of any state changes, without the need for the subject to keep track of the observers.
In this lab, we will work on the problem of creating a notification system in which a message needs to be broadcasted to multiple subscribers.
Video
Objectives
In this lab you will
understand a real-world scenario and choose when to apply the appropriate design pattern.
If you do not like to use an IDE, you may use any text editor (e.g., VS Code, jEdit, etc.) and the Javac compiler.
Apache Maven is a build automation tool to build projects and manage their dependencies.
Getting Started
If your instructor is using GitHub classroom, you will need to accept the assignment using the link below, clone the template repository, and import it as a project into your IDE.
A developer is working on an app that monitors the price of a product on an online store. The app allows users to receive a notification when the price of a given product drops. These notifications can be received via Email, Facebook, Whatsapp, SMS, etc. He wanted to support multiple notification services in the future. Thus, his design goal is to build up a system that is extensible and efficient where he can add a new notification service (e.g, push notification, Voice calls, etc.) without making additional changes to existing working services.
Below is the web page he wants to regularly check the price on:
If your instructor is using GitHub classroom, then you should click on your class submission link,
link your GitHub username to your name if you have not already done so, accept the assignment, clone the
repository into your local
development environment, and push the code to the remote repository on GitHub. Please make sure that your
written
answers are included in either a README (Markdown) file or a PDF file.
Lab dues dates are listed on GitHub classroom unless otherwise
noted.
If your instructor is using GitHub classroom, your submission will be
auto-graded
by running the included unit tests as well as manually graded for correctness, style, and quality.
How to submit your lab to GitHub Classroom
The video below demonstrates how to submit your work to GitHub classroom
Extra Task [Optional]
If you are done with this activity, you may enable a continuos integration tool such as CircleCI ↗ to automatically run your JUnit test upon code changes. You may also add more unit tests to increase code coverage. Please embed the badge that shows the status of your build and test (passing/failing) as well as the coverage percentage into your README file (e.g.,
and ). Please be sure to fork the repository or push to a remote repository under your own account, so you can enable the integration of CI tools in your own account.