In the last demo, you learned about the Observer pattern. You updated ContactCard to be a subject and ContactsBook to be an observer. Whenever the book receives a new contact to save, it subscribes to it so it receives updates whenever any of the contact card’s values change.
You updated ContactCard to announce it has been updated in each of the methods that change its values. You also updated ContactsBook to print the index of the card that has been updated.
Here are the things you learned in this lesson:
Design patterns are solutions for common challenges related to software design. They’re intended to be ready-to-go, optimized specifications for you to implement, saving you the effort of designing a solution.
The Singleton pattern is a specification for objects that should be only instantiated once, then be commonly shared across the whole system. There should be no way to accidentally create other instances.
The Factory pattern abstracts the implementation details and child types for the initialization of different objects that have a common usage. Each factory function takes care of the setup of the object and returns it as its base type, so your system doesn’t know the underlying types you define. This simplifies your object creation process.
The Observer pattern is a specification that lets different parts of the system receive updates when individual objects change — without creating tight coupling between those parts. This pattern is very useful for reflecting changes to the data in the user interface.
In the next lesson, you’ll learn some principles that will guide you to write cleaner, clearer and more reusable code.
See forum comments
This content was released on Oct 17 2023. The official support period is 6-months
from this date.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.