** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil...

13
** Reuse Activities ** Selecting Design Patterns and Components ( Part 1 ) D o n e b y Safaa khalil Meqdad

Transcript of ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil...

Page 1: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

**Reuse Activities** Selecting Design Patterns

and Components(Part 1 )

Done by

Safaa khalil Meqdad

Page 2: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

Outline

• Introduction

• Sources of Changes

• Design Patterns

Page 3: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

.. Sources of Changes ..

• New vendor or new technology

• New implementation • New views

• Errors

Page 4: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

.. Design Patterns ..• Bridge Design Pattern

• Adapter Design Pattern

• Strategy Design Pattern

• Abstract Factory Design Pattern

Page 5: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

** Bridge Design Pattern **

• decouple the interface from an implementation so that implementations can be substituted possibly at run time .

• From figure (1) the client just deal with Abstraction class and completely shielded from both abstraction implementor and concrete implementation .

• Bridge design pattern fills the gap between the interface and its implementation .

Page 6: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

Arena

LaegueStore LaegueStoreImplementator

StubStoreImplementor

XMLStoreImplementor

JDBCStoreImplementor

Figure (1)

Abstraction class

Page 7: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

** Adapter Design Pattern **

• The Adapter converts the interface of a legacy system into an interface expected by the user ..

• From figure ( 2 ) the Adapter class (MyStringComparator) provides the interface expected by the client ,and delegates the request the client request to the Legacy class (MyString) and perform any necessary conversions .

• Adapter works with Legacy Class and all of its subclasses.

• Client and Legacy class can work together with out any modification on both sides .

Page 8: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

ArrayComparator

compare ) (

MyStringComparator

compare ) (

MyString

graeterThan) ( eqauls ) (

Figure (2)

Adapter class

Legacy class

Page 9: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

** Strategy Design Pattern **

• Decouple a policy-deciding class from a set of mechanisms so that different mechanisms can be changed transparently from the client.

• From figure (3) .. the network access protocols implementations are encapsulated with a strategy pattern to decouple the policy from selecting a network interface

• New algorithms can be added .

Page 10: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

Application

LocationManager

NetworkConnection

send ) (receive ) (setNetworkInterface ) (

NetworkInterface

open) ( close) ( send) ( receive) (

Ethernet

Open) ( close) ( send) ( receive) (

WaveLAN

Open) ( close) ( send) ( receive) (

UMTS

Open) ( close) ( send) ( receive) (

Figure (3)

Strategy class

Policy

Page 11: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

** Abstract Factory Design Pattern **

• The Abstract Factory shield the client from different platforms that provide different implementations for the same set of concepts ..

• Client deals with interface provided by the AbstractFactory figure (4).

• Client can change platforms easier .

• Adding new product is difficult since new realization for each factory must be created.

Page 12: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

Blind

LuxmateBulbEIBBulbLuxmateBulbEIBBulb

LightBulb

HouseFartory

createBulb ) (craeteBlind ) (

EIBFactory

createBulb) ( craeteBlind) (

LuxmateFactory

createBulb) ( craeteBlind) (

TheftApplication

Figure (4)

AbstractFactory class

Page 13: ** Reuse Activities ** Selecting Design Patterns and Components (Part 1) Done by Safaa khalil Meqdad.

SummaryPhraseDesign Pattern

“Must Support future protocols”Bridge Design Pattern

“Must deal with existing systems or reuse Legacy systems”

Adapter Design Pattern

“Platform independency” .. “Manufacturers independency”

AbstractFactory Design Pattern

“Must allow different algorithms to be interchanged at runtime”

Strategy Design Pattern