In the previous lesson, you created ContactsBook with the static property, current, so the different modules of the program can all access the same list of contacts. However, nothing in your implementation prevents different teams and team members from using your code to create different instances from ContactsBook. This would cause the program to end up with multiple different contact lists.
Your first thought might be that it’s their fault because they misused your code. You wouldn’t be wrong thinking so, but it’s always safer to secure your code against misuse. You need the class itself to enforce that it can never be instantiated more than once. To do this, you’ll use the appropriately named Singleton pattern.
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.