Structural Design Patterns: Example: When A Person Traveling From Lahore To Islamabad He Need To

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Structural design patterns

These design patterns are all about Class and Object composition. .

 Adapter
Match interfaces of different classes

Example: When a person traveling from Lahore to Islamabad he need to


use plug adapter for charging your laptop.the same kind of adapter is
needed for connecting some devices to your laptop: the USB adapter

 Bridge
Separates an object’s interface from its implementation

Example:

I want to send a message to the corresponding person. i can Email the


message or SMS the message to the corresponding person. So, you have
two options to send the message and the abstraction will use one of the
implementations to send the message to the corresponding person.Later
if you want to add any new implementation to the Implementation layer
then it will not affect the Abstraction layer. This is one of the best
examples of bridge design pattern.

 Composite
A tree structure of simple and composite objects

Example:

Menu items in GUI screens is the real time example of composite design
pattern.

 Decorator
Add responsibilities to objects dynamically

Example:
I have a business .I want new product in my business. I no want to change
the architecture of existing .I change the design of the architecture for the
newly add product with affecting the existing.

 Facade
A single class that represents an entire subsystem

Example: You are a arrangement incharge of a party.you have to


book a hotel and handle all other arrangement .you have done all
arrangement by talking to relevant folks .you go and talk to an event
manger who handle this for you.he will make sure that they talk to
individual service providers and get the best deal for you.

 Flyweight
A fine-grained instance used for efficient sharing

Example: Library have dedicated shelves with the newest and most
popular publication . this is a cache. First you can take a look at the
dedicated shelves for the book you are looking for, if not find then you
ask the librarian.

 Private Class Data


Restricts accessor/mutator access

Example:

A person you cook a stew for her friends . he want to prevent your friends
from consuming the stew by tasting it while he is cooking, otherwise
there will be no more stew for dinner later

 Proxy
An object representing another object

Example: A person use Facebook,he 1st register with the FB and the
log on each session.once logged on, he has access to your friend’s
pages. All action that perform originate on browsers .the object are FB
pages the proxies are the mechanisms that allow registration and log out.

You might also like