YouTube Summaries | 8 Design Patterns Every Developer Should Know
October 30th, 2023
Introduction:
As always, this summary will focus on cementing the learnings that I took from watching the video above.
Creational Patterns
- The “Factory” pattern allows you to create objects without worrying about their construction details.
- Similar to ordering a burger without worrying about ingredients
- The “Builder” pattern provides more control over object creation and allows you to chain methods to customize object attributes.
Builder Pattern
- Focuses on creating objects with individual methods for setting parameters
- Works well when chaining methods to build custom objects
Singleton Pattern
- This pattern ensures that a class has only one instance and is commonly used for managing application state.
- A practical example of using a singleton would be for something like managing user login status.
Observer (Pub-Sub) Pattern
- Similar to the way YouTube notifies subscribers when a new video is uploaded, the Observer pattern allows multiple subscribers to be notified in real-time when an event occurs.
- The pattern can be implemented with subjects (publishers) and subscribers (listeners).
Iterator Pattern
- It simplifies traversing elements in objects, and custom iterators can be defined for more complex data structures.
- Iterator pattern allows abstraction for iteration through data structures
- A simple example would be iterating through objects in a list
Strategy Pattern
-
This pattern allows you to modify or extend a class’s behavior without changing its code. It’s illustrated by filtering arrays using different strategies.
-
Follows the open closed principle in that it allows for strategies to alter original data structures without modifying the original data itself
Adapter Pattern
- The Adapter pattern is used to make incompatible objects work together, like using adapters for different types of cables or connectors.
- Would be the software analog of a Micro USB plug using a Micro USB-to-USB adapter to plug into a USB port
Facade Pattern
- The Facade pattern hides complex underlying details from programmers, providing a simpler and more abstract interface to interact with.