Design Patterns Flashcards
In what groups can we divide the design patterns?
Creational, Structural and Behavioral design patterns
Why should we use creational patterns?
Creational patterns provide more flexibility in how the objects are actually created
Why should we use structural patterns?
Structural patterns deal with how inheritance and composition can be used to provide extra cuntionality
Why should we use behavioral patterns?
Behavioral patterns are about communication and assignment of responsibilities between our objects
What is the proxy pattern?
- Structural design pattern
- Provides a substitute for another object and controls access to that object, allowing you to perform something before or after the request reaches the original object
- Can be used to e.g. cache the info of downloaded videos
What is the decorator pattern?
- Structural design pattern
- The decorator pattern lets you attach new behaviors to an object by placing this object inside a special wrapper that contains these behaviors
What is the adapter pattern?
- Structural design pattern
- It allows objects with incompatible interfaces to collaborate with one another
- Idea: This pattern takes all of our XML data and transforms it to JSON making it compatible with the third party library we are making use of
What is the bridge pattern?
- Structural design pattern
- The bridge pattern lets you split a large class into two separate hierarchies which can be developed independently -> divide and organize a single class that has multiple variants of some functionality into two hierarchies: abstractions and implementations
What is the singleton pattern?
- Creational design pattern
- This pattern ensures that only one instance of its kind exists and provides a single point of access to it within our whole application
What is the factory pattern?
- Creational design pattern
- This pattern makes it easy to extend the product construction code independently from the rest of the application -> Allows introducing new products without breaking existing code
- Use this pattern if you have no idea of the exact types of the objects your code will work with
What is the abstract factory pattern?
- Creational design pattern
- The abstract factory pattern allows you to produce families of related objects without specifying their concrete classes
- Many designs start by using the factory method pattern and later evolve toward an abstract factory pattern
What is the builder pattern?
- Creational design pattern
- The builder pattern produces different types and representations of an object using the same construction process
- The builder pattern suggests that we extract the object construction or creation code out of its own class and move it to separate objects called builders
What is the prototype pattern?
- Creational design pattern
- The prototype pattern delegates the object duplication or cloning process to the actual objects that are being cloned
- Use the prototype pattern when your code should not depend on the concrete classes of the objects that you need to copy or duplicate