Uploaded by mohomadrinas2002

DESIGN PATTERNS

advertisement
DESIGN PATTERNS
1. Design patterns in OOP
The most important component of software engineering is design patterns as they offer a generic,
repeatable solution to a problem that arises frequently in software design. Typically, they
embody several optimal methodologies used by seasoned object-oriented software practitioners.
2. Creational Design Patterns
2.1.Singleton Pattern
The Singleton pattern ensures that a class has only one instance and provides a global point of
access to it. This is particularly useful in scenarios where a single point of control or
coordination is necessary, such as managing a global configuration or a centralized resource.
2.2.Factory Method Pattern
In the Factory Method pattern, a common interface is defined for creating objects, but the
specifics of the object instantiation are delegated to subclasses. This allows the client code to
depend on the interface rather than the concrete implementation, promoting flexibility and
extensibility.
2.3.Abstract Factory Pattern
The Abstract Factory pattern goes a step further by providing an interface for creating families of
related or dependent objects. This is beneficial in situations where the system needs to be
configured with multiple sets of related objects.
2.4.Builder Pattern
The Builder pattern separates the construction of a complex object from its representation. It
allows the same construction process to create different representations of the object. This is
especially useful when the construction process is complex and involves multiple steps.
2.5.Prototype Pattern
The Prototype pattern involves creating new objects by copying an existing object, known as the
prototype. This is advantageous when the cost of creating a new instance is more expensive than
copying an existing one.
2.6.Object Pool Pattern
The Object Pool pattern manages a finite set of instances of a class, allowing them to be reused
rather than created and destroyed on demand. This is beneficial in scenarios where the cost of
initializing and destroying objects is high and reusing them can improve performance.
3. Structural Design Patterns
3.1.Adapter Pattern
The Adapter pattern allows the interface of an existing class to be used as another interface. This
is useful when integrating new components that have incompatible interfaces with the existing
codebase.
3.2.Bridge Pattern
The Bridge pattern separates abstraction from implementation, allowing them to evolve
independently. This is particularly useful when you want to avoid a permanent binding between
an abstraction and its implementation.
3.3.Composite Pattern
The Composite pattern composes objects into tree structures to represent part-whole hierarchies.
It treats individual objects and compositions of objects uniformly. This is beneficial when clients
need to treat individual objects and compositions of objects uniformly.
3.4.Decorator Pattern
The Decorator pattern dynamically attaches additional responsibilities to an object. It provides a
flexible alternative to subclassing for extending functionality. This is useful when you want to
add new functionalities to objects without altering their structure.
4. Advantages of Using Design Patterns
Reusability: By using Inheritance, they helps in making the code reusable and hence we can use
them in multiple projects.
Transparent: It improves the transparency of the code for all the developers who are going to
use it in future.
Established Solution: We can blindly believe on the solution provided by Design Patterns as
they are well-proved and testified at critical stages.
Established Communication: Design patterns make communication between designers more
efficient. Software professionals can immediately picture the high-level design in their heads
when they refer the name of the pattern used to solve a particular issue when discussing system
design.
Efficient Development: Design patterns helps in the development of the highly cohesive
modules with minimal coupling.
Download