On Design Patterns
Arvind Saraswat
Storage Solution Architect & Pre-Sales || Storage Systems and Solutions || Large Scale Distributed Systems || Intelligent Networks || 2x Author ||
Design patterns are a way to solve common problems in software design. There are over 20 design patterns, but only a few are commonly used. It is important to know these patterns well because they can help you write more modular, reusable, and maintainable code.
Design patterns can be divided into three main types: creational, structural, and behavioral.
??. ???????????????????? ????????????????
Creational patterns deal with object creation. They provide a way to create objects in a flexible and extensible way. Important patterns in this group are:
????????????????: The Factory pattern is a way to create objects without exposing the instantiation logic to the client. This can be useful when you want to create different types of objects depending on the situation.
????????????????????: The Singleton pattern ensures that a class has only one instance. This can be useful when you need to coordinate actions across the system or when you want to ensure that there is only one copy of a resource.
??. ???????????????????? ????????????????
Structural patterns deal with the composition of objects. They provide a way to combine objects to create larger structures. Important patterns in this group are:
????????????????: The Adapter pattern is a way to make two incompatible interfaces work together. It does this by wrapping an existing class with a new interface that is compatible with the client's interface. This can be useful when you need to use an existing class that does not have the interface you need.
领英推荐
??????????????: The Fa?ade pattern is a way to simplify a complex subsystem. It does this by providing a single interface that hides the complexity of the subsystem from the client. This can be useful when you need to make a subsystem easier to use.
????????????????????: The Decorator pattern is a way to add new functionality to an object without modifying the object's code. It does this by wrapping the object with a decorator class that adds the new functionality. This can be useful when you need to add new functionality to an object dynamically.
????????????: The Proxy pattern is a way to control access to an object. It does this by creating a proxy object that stands in for the real object. The proxy object can then be used to control access to the real object. This can be useful when you need to protect the real object from unauthorized access.
??. ???????????????????? ????????????????
Behavioral patterns deal with the communication between objects. They provide a way to define how objects interact with each other. Important patterns in this group are:
????????????????: The Command pattern is a way to encapsulate a request as an object. This allows you to treat the request as data and pass it around your system. It can also be used to queue requests or to undo requests.
?????????????????? ????????????: The Template Method pattern is a way to define the skeleton of an algorithm in a method. This method can then be overridden by subclasses to provide different implementations of the algorithm. This can be useful when you want to keep the overall structure of an algorithm the same but allow different implementations of the algorithm.
??????????????????: The Strategy pattern is a way to encapsulate a family of algorithms. This allows you to choose the algorithm that is most appropriate for the current situation. It can also be used to make your code more flexible and extensible.
??????????????????: The Observer pattern is a way to define a one-to-many dependency between objects. This means that when one object changes state, all of its dependents are notified and updated automatically. This can be useful when you want to keep track of changes to objects in your system.
Vice President Test (Intelligent Cockpit), Harman Automotive, IEEE Sr. Member, Author
1 年Arvind Saraswat you explained the creational, structural and behavioural design pattern in very clear manner. Great job