AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Observer design pattern c1/22/2024 ![]() ![]() The class that will implement the Subject interface will act as a News Station. We will then create two concrete classes that will implement the virtual methods of each interface. The Observer interface will have one virtual method that will be updated with information from the Subject object. The Subject interface will contain virtual methods that will register, remove and notify an Observer object. We will create two interfaces whose names are: Subject and Observer. We are going to make use of abstract classes to implement the concept of Interfaces. We are going to implement the Observer Design Pattern in C++. The newspaper updates the subscriber with news, the subscriber reads them. The newspaper nor the subscriber have internal knowledge about each other, yet they are able to interact. This essentially means that your classes should be loosely coupled.Ī good analogy that helps understand how the Observer Design Pattern works is a newspaper subscription. It means that your classes should be able to interact with each other, but have little knowledge about each other. Strive for loosely coupled designs between objects that interact. The Observer Design Pattern follows one of the most important principles of Object Oriented Programming. ![]()
0 Comments
Read More
Leave a Reply. |