marcandrewb
2/27/2018 - 2:18 AM

Design Patterns Cheatsheet

Design Patterns Cheatsheet

Decorator: Need to dynamically add functionality to objects? With Decorator, you can do this without affecting the behavior of other objects from the same class. Great for keeping classes simple and adding on new combinations of behavior at runtime.

Observer: Need your objects to be notified when events happen? With the Observer pattern you can get notified in a way that keeps everything in your design flexible and loosley coupled.

Dependency Injection: Does your software depend on services from libraries to get things done, but you don’t want to be too dependent on any one implementation of a service? Dependency Injection keeps your code loosely coupled from modules so you can change your mind later and use a different service without having to rewrite a bunch of code.

Adapter: Need to isolate your code from two or more APIs? Adapters are commonly used.

Model-View-Controller (MVC): This is the go-to pattern for building systems with user interfaces (views). The MVC pattern allows you to keep your UI, business logic, and model code all nice and separate.

Module: This pattern helps keep all your library code separate from your own code with a handy public interface to all the functionality you need.

Singleton: The Singleton pattern is used when you need to have one, and only one, of an object. Use it to represent critical resources that can only exist once in your app.

Iterator: Need to be able to iterate through a collection of things without knowing the specifics of the things? Use the Iterator pattern.

Command: Want to delegate work to other objects, without specifying exactly who should do it, and without telling them how to do their job? Use the Command pattern.