Conclusion

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 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
Download course materials from Github
Previous: Demo 3 Next: Quiz: Design Patterns