Instruction 1

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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
Download course materials from Github
Previous: Introduction Next: Demo 1