Design Pattern: Adapter Composite

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

DESIGN

PATTERN:
ADAPTER
COMPOSITE
Group 2

Bibek Shiwakoti Bikesh Shrestha Uddhav Chalise Rupesh Giri


Introduction
What is Design Pattern?

● A design pattern is a general repeatable solution to a commonly


occurring problems in software development. It represents the best
practices used by experienced object-oriented software developers.

● Design patterns are solutions to general problems that software


developers faced or may face during software development. These
solutions were obtained by trial and error by numerous software
developers over quite a substantial period of time.
Usage of Design Pattern
Why do we use Design Pattern?

• We use design patterns because they make our job easier


and it lets us write better codes more quickly and effectively.

Design patterns have been evolved over a long period of time


and they provide best solutions to certain problems faced
during software development. So, learning these patterns
helps unexperienced developers to learn software design in
an easy and faster way.
Benefits of Design Pattern
● They are reusable in multiple projects.
● They provide the solutions that helps to define the system
architecture.
● They capture the software engineering experiences.
● They provide transparency to the design of an application.
● They are well-proved and testified solutions since they have
been built upon the knowledge and experience of expert
software developers.
● Design patterns don't guarantee an absolute solution to a
problem. They provide clarity to the system architecture and the
possibility of building a better system.
Constraints of Design Pattern
● Becomes too large in case of a complex page.

● Hard in automated testing.

● It cannot be used with Single Page Application (SPA).


Types of Design Pattern in Java

Creational Structural Behavioral

• Singleton • Adapter • Mediator


• Observer
• Factory • Composite • Strategy
• Proxy • Command
• Abstract • State
Factory • Fly Weight • Visitor
• Façade • Iterator
• Builder • Interpreter
• Bridge • Memento
• Prototype • Decorator etc.
Types of Design Pattern in Java

Structural

• Adapter
• Composite
Structural Design Patterns

• Structural design patterns are all about Class and Object composition.
Structural class-creation patterns use inheritance to compose
interfaces while structural object-patterns defines ways to compose
objects to obtain new functionality.

• In another word, Structural Design Patters are used to design objects to


satisfy particular project constraints. These works with the way objects
are connected with other objects to ensure that changes in the system
do not require changes to those connections.
Adapter
• Adapter pattern is a simple pattern that provides a wrapper for a class
or object that uses a different interface, much like an electrical adapter
can convert three-prong to two-prong plugs.

• Adapter matches interfaces of different classes. Adapter pattern works


as a bridge between two incompatible interfaces. This type of design
pattern comes under structural pattern as this pattern combines the
capability of two independent interfaces.
Figure: Adapter
Why do we use Adapter in Structural Design Pattern?
• Converts the interface of a class into another interface. Adapter lets
classes work together that couldn't otherwise because of incompatible
interfaces.

• Wraps an existing class with a new interface.

• Helps to match an old component to a new system.


Benefits of Adapter Constraints of Adapter

● It allows two or more ● Harder to override adoptee


previously incompatible behavior.
objects to interact.
● Requires more code to
● It allows reusability of existing implement properly.
functionally.
Composite
• Composite Pattern describes a tree-like structure in which individual
parts have the same interface as the whole pattern. Any leaf or sub-tree
of the tree has the same interface as the entire tree. There is no fixed
limit on the number of nodes in the three.

• It is a tree structure of simple and composite objects. This pattern


creates a class that contains group of its own objects. This class
provides ways to modify its group of same objects.
Figure: Composite
Benefits of Composite Constraints of Composite

● Design flexibility ● Composites are


heterogeneous.
● Durability
● Composites are relatively
● Corrosion resistance anisotropic.

● Low relative investment


References
● www.wikipedia.com

● www.tutorialspoint.com

● www.geeksforgeeks.com

● www.c-sharpcorner.com

● www.dzone.com
THANK YOU !
Any Questions ?

You might also like