Programming Paradigms + Design Patterns
PROGRAMMING PARADIGMS
OOPS DESIGN PATTERNS
Design patterns are reusable solutions to common problems encountered in software design. They represent best practices and proven solutions to design and implement software systems effectively.
Design patterns are categorized into three main groups: creational, structural, and behavioral patterns.
Creational Patterns: Creational patterns deal with the creation of objects and provide ways to instantiate objects in a manner suitable for a given situation. They help in making a system independent of how its objects are created, composed, and represented. Common creational patterns include:
Singleton Pattern: Ensures that a class has only one instance and provides a global point of access to that instance.
Factory Method Pattern: Defines an interface for creating objects, but allows subclasses to alter the type of objects that will be created.
Abstract Factory Pattern: Provides an interface to create families of related or dependent objects without specifying their concrete classes.
Builder Pattern: Separates the construction of a complex object from its representation, allowing the same construction process to create different representations.
Structural Patterns: Structural patterns focus on simplifying the structure of a system by identifying simple ways to realize relationships between entities. They help in composing objects and classes into larger structures while keeping these structures flexible and efficient. Common structural patterns include:
Adapter Pattern: Allows objects with incompatible interfaces to work together by providing a wrapper with a compatible interface.
Decorator Pattern: Attaches additional responsibilities to an object dynamically, providing a flexible alternative to subclassing for extending functionality.
Composite Pattern: Composes objects into tree structures to represent part-whole hierarchies. It allows clients to treat individual objects and compositions of objects uniformly.
Proxy Pattern: Provides a surrogate or placeholder for another object to control access to it or add additional functionality.
Behavioral Patterns: Behavioral patterns focus on the interaction between objects and how they communicate with each other. They help in defining algorithms and communication patterns among objects, making the system more flexible and reusable. Common behavioral patterns include:
Observer Pattern: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Strategy Pattern: Defines a family of algorithms, encapsulates each one, and makes them interchangeable. It allows the algorithm to vary independently from clients that use it.
Command Pattern: Encapsulates a request as an object, thereby allowing for parameterization of clients with queues, requests, and operations.
State Pattern: Allows an object to alter its behavior when its internal state changes. The object will appear to change its class.
These design patterns provide solutions to recurring design problems in software development and promote code reusability, flexibility, and maintainability.