Design Pattern Basic Flashcards
Types of design patters
Creational, Structural, Behavioral
Creational
designed for class instantiation can be class or object creational patterns (e.g. singleton design)
Structural
increase functionality of the classes involved without changing much of its composition (e.g. Decorator Design)
Behavioral
take care of effective communication and the assignment of responsibilities between objects. Chain of responsibility, iterator, mediator, strategy
Factory
a class handling creation of different object (e.g. ShapeFactory which returns different shape based on the info passed in) Used when a class cannot anticipate the type of objects it needs to create before hand. Allow creation of object without knowing the details of it.
Abstract factory
A base class with abstract methods defining methods for the objects that should be created. Each factory class which derives the base class can create their own implementation of each object type.
Aggregation
child can exits independently of the parent
Composition
child cannot exist independent of the parent
Singleton Pattern
is a creational design pattern that lets you ensure that a class has only one instance, while providing a global access point to this instance. Code becomes so tightly coupled that you can't make changes without affecting everything associated with it. It also doesn't support inheritance and can be easily broken.
Static Class
only provides static methods, does not provide an object
Builder
builds complex object using simple objects step by step and use builder class to build the final object. It is a creational design pattern. (E.g. building a meal)
Prototype pattern
Creational design patter that lets you copy existing objects without making your code dependent on their classes. E.g. when you want to copy an object but the some fields is private and can’t be accessed.
Adapter Pattern
Bridge between two incompatible interface. Structural Design Pattern. E.g. MediaPlayer for MP3, MP4 files
Bridge Pattern
is a structural design pattern that lets you split a large class or a set of closely related classes into two separate hierarchies—abstraction and implementation—which can be developed independently of each other. E.g. Remote and a set of devices
Proxy
a class represents functionality of another class. It controls access to the original object. Have a concrete class and proxy class implementing same interface. The proxy class then contains the concrete class. It is a Structural design pattern. Similar to an API.