My design patterns

Preview:

DESCRIPTION

I presented my understanding on few design patterns to my team @ex employer. They liked it coz of its simplicity and crips and clear.

Citation preview

Design Patterns

Shailesh Kumar S

Agenda

Structural Design Patterns:AdapterDecoratorBridgeFacade

Structural Patterns What?

Defines composition between entities to build larger systems.

Why? Helps in understanding the relationship between

classes and objects.

How? By using following Patterns:

Adapter, Facade, Bridge, Decorator, etc.

Adapter Pattern What?

Translate one interface of a class into a compatible interface.

Why? And old legacy class needs to be reused, but its

interface is different than application expects.

Example 1:

Example 2:

Decorator Pattern What?

Defines attaching new responsibility to the object dynamically.

Why? Helps in wrapping an existing object with another

object with out breaking the interface or other objects.

Example 1:

Example 2:

Bridge Pattern What?

Separates objects interface and its implementation.

Why? Both abstraction and implementation can vary

independently. Avoiding hard binding between abstraction and

implementation. Reduce number of sub classes and this reduction

in code size.

Example: House electrical equipment and switch Text file storage and representation across

operating systems.

Facade Pattern

What? An Higher level interface to a complex sub-

system to simplify communication.

Why? Re-structuring a complex system into less

complex sub-systems

Reduce dependencies between sub-systems.

Example:

Client Object 1 Client Object 2

Client objects

Sub-systems objects

Ordering System

Billing System

Query System

Client Object 3

With Facade Pattern:

Example:

Customer Service Support system

Library Management system

Client objects

Sub-system objects

Facade

Client Object 2Client Object 1

Client Object 3

Billing System

Ordering System

When to choose what:Adapter: You want to use an existing class, and its interface does not

match the one you need.

Decorator: When you want to enhance the responsibilities of an object.

When extension for an object via sub-classing is complex/tedious.

Bridge: Only applied before the classes are designed.

When both side of the interfaces can vary independently.

Facade:

When you want to define new interface for a group of objects with out adding new functionality.

When you want to represent 1 object for a group of objects to simplify communication.

Questions?

Recommended