my design patterns

15
Design Patterns Shailesh Kumar S

Upload: zenwalker

Post on 28-Jun-2015

2.070 views

Category:

Technology


0 download

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.

TRANSCRIPT

Page 1: My design patterns

Design Patterns

Shailesh Kumar S

Page 2: My design patterns

Agenda

Structural Design Patterns:AdapterDecoratorBridgeFacade

Page 3: My design patterns

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.

Page 4: My design patterns

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.

Page 5: My design patterns

Example 1:

Example 2:

Page 6: My design patterns

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.

Page 7: My design patterns

Example 1:

Example 2:

Page 8: My design patterns

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.

Page 9: My design patterns

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

operating systems.

Page 10: My design patterns

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.

Page 11: My design patterns

Example:

Client Object 1 Client Object 2

Client objects

Sub-systems objects

Ordering System

Billing System

Query System

Client Object 3

Page 12: My design patterns

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

Page 13: My design patterns

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.

Page 14: My design patterns

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.

Page 15: My design patterns

Questions?