Design Pattern
By Julie Iskander
MSc. Communication and Electronics
Outlines
Lecture 3
• Structural Design Patterns
• Adapter
• Bridge
• Composite
• Decorator
• Façade
• Proxy
• Flyweight
Structural Patterns
adapter DP
(Class-Structural DP)
adapter DP
(Class-Structural DP)
adapter DP
(Class-Structural DP)
• Adapter in OO
adapter DP
(Class-Structural DP)
• What
• A design that enables a noncompliant interface to be used
through an intermediary, which manages an adaptation
process to effect compliance.
• Where
• A requirement to integrate with a noncompliant interface or a
requirement for one design to leverage the functionality of
another design.
• Why
• To reuse or integrate existing functionality, or adapt to change
in business requirements that necessitates reengineering
design or functionality.
• How
• An intermediary class is used to map the desired functionality
from the source interface to that required by the target
adapter DP
(Object-Structural DP)
adapter DP
(Class-Structural DP)
adapter DP
(Object-Structural DP)
Bridge DP
(Object – Structural DP)
• What
• Decouple an abstraction from its implementation so that
the two can vary independently.
• Avoid a permanent binding between an abstraction and
its implementation or to hide implementation from client
• Why
• Decoupling interface and implementation.
• How
• Abstraction forwards client requests to its Implementor
object.
Bridge DP
(Object – Structural DP)
Bridge DP
(Object – Structural DP)
Bridge DP
(Object – Structural DP)
• Example
• A bank Account may be a saving or a current
account. A bank account may also be a
student account or a child account or a
normal account
• Note that:
• Abstract Factory can create a particular
Bridge
• Assignment: Show how can this be
done?
Bridge DP
(Object – Structural DP)
Bridge Vs. Adapter
• Bridge DP:
• Meant to separate an interface from its
implementation, to vary easily and
independently
• Adapter DP:
• Meant to change the interface of an existing
object
• It is applied to systems after they’re designed.
• Makes unrelated classes work together.
Composite DP
(Object – Structural DP)
• What
• A design that ensures that an entity and a composite of
entities expose the same interface.
• Where
• A requirement to treat simple and composite objects alike
• Why
• To organize entities into hierarchies, that contain single
entities and composite entities
• How
• A common interface is inherited by a composite and an
entity
Composite DP
(Object – Structural DP)
Composite DP
(Object – Structural DP)
A parent class should
define operations that
are meaningful to all
subclass
Composite DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
• What
• Attach additional responsibilities to an object
dynamically.
• Where
• To add responsibilities to individual objects dynamically,
without affecting other objects.
• For responsibilities that can be withdrawn.
• Why
• Add optional responsibilities
• How
• Abstraction forwards client requests to its Implementor
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
decorator DP
(Object – Structural DP)
• Decorator & Adapter:
• A decorator changes an object responsibility
while an adapter changes its interface
• Decorator & Composite:
• A decorator adds responsibility while a
composite is intended for object aggregation
decorator DP
(Object – Structural DP)
Façade DP
(Object – structural dp)
• What
• A design to hide the complexity of many interface behind
a simple and uniform interface.
• A requirement for a high-level abstraction that is simple
to use.
• Why
• Software becomes complex as it seeks to interact with
many interfaces, systems, or subsystems.
• How
• Managing multiple interfaces is delegated to a facade
class that hides the complexity and presents a simple
interface.
Façade DP
(Object – structural dp)
Façade DP
(Object – structural dp)
Proxy DP
(Object – structural dp)
• What
• Represents or regulates access to an object that is scarce or remote.
Provide a surrogate or placeholder for another object to control
access to it.
• Where
• Access needed to be regulated or access to a principal needs to be
distributed.
• Why
• To regulate client code access to a given resource; or for remote
access to functionality.
• How
• A proxy class is derived from the same base class as the principal
class. The proxy class uses composition—it creates a member
instance of the principal—to expose the functionality of the principal
through a set of wrapper methods or properties. The client code
creates an instance of the proxy class that regulates or distributes
access to the functionality of the principal.
Proxy DP
(Object – structural dp)
Proxy DP
(Object – structural dp)
Report #2:
Flyweight DP
N.B. Hand Written 

Design Pattern lecture 3

  • 1.
    Design Pattern By JulieIskander MSc. Communication and Electronics
  • 2.
    Outlines Lecture 3 • StructuralDesign Patterns • Adapter • Bridge • Composite • Decorator • Façade • Proxy • Flyweight
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
    adapter DP (Class-Structural DP) •What • A design that enables a noncompliant interface to be used through an intermediary, which manages an adaptation process to effect compliance. • Where • A requirement to integrate with a noncompliant interface or a requirement for one design to leverage the functionality of another design. • Why • To reuse or integrate existing functionality, or adapt to change in business requirements that necessitates reengineering design or functionality. • How • An intermediary class is used to map the desired functionality from the source interface to that required by the target
  • 8.
  • 9.
  • 10.
  • 11.
    Bridge DP (Object –Structural DP) • What • Decouple an abstraction from its implementation so that the two can vary independently. • Avoid a permanent binding between an abstraction and its implementation or to hide implementation from client • Why • Decoupling interface and implementation. • How • Abstraction forwards client requests to its Implementor object.
  • 12.
    Bridge DP (Object –Structural DP)
  • 13.
    Bridge DP (Object –Structural DP)
  • 14.
    Bridge DP (Object –Structural DP)
  • 15.
    • Example • Abank Account may be a saving or a current account. A bank account may also be a student account or a child account or a normal account • Note that: • Abstract Factory can create a particular Bridge • Assignment: Show how can this be done? Bridge DP (Object – Structural DP)
  • 16.
    Bridge Vs. Adapter •Bridge DP: • Meant to separate an interface from its implementation, to vary easily and independently • Adapter DP: • Meant to change the interface of an existing object • It is applied to systems after they’re designed. • Makes unrelated classes work together.
  • 17.
    Composite DP (Object –Structural DP) • What • A design that ensures that an entity and a composite of entities expose the same interface. • Where • A requirement to treat simple and composite objects alike • Why • To organize entities into hierarchies, that contain single entities and composite entities • How • A common interface is inherited by a composite and an entity
  • 18.
  • 19.
  • 20.
    A parent classshould define operations that are meaningful to all subclass Composite DP (Object – Structural DP)
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
    decorator DP (Object –Structural DP) • What • Attach additional responsibilities to an object dynamically. • Where • To add responsibilities to individual objects dynamically, without affecting other objects. • For responsibilities that can be withdrawn. • Why • Add optional responsibilities • How • Abstraction forwards client requests to its Implementor
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
    • Decorator &Adapter: • A decorator changes an object responsibility while an adapter changes its interface • Decorator & Composite: • A decorator adds responsibility while a composite is intended for object aggregation decorator DP (Object – Structural DP)
  • 34.
    Façade DP (Object –structural dp) • What • A design to hide the complexity of many interface behind a simple and uniform interface. • A requirement for a high-level abstraction that is simple to use. • Why • Software becomes complex as it seeks to interact with many interfaces, systems, or subsystems. • How • Managing multiple interfaces is delegated to a facade class that hides the complexity and presents a simple interface.
  • 35.
    Façade DP (Object –structural dp)
  • 37.
    Façade DP (Object –structural dp)
  • 38.
    Proxy DP (Object –structural dp) • What • Represents or regulates access to an object that is scarce or remote. Provide a surrogate or placeholder for another object to control access to it. • Where • Access needed to be regulated or access to a principal needs to be distributed. • Why • To regulate client code access to a given resource; or for remote access to functionality. • How • A proxy class is derived from the same base class as the principal class. The proxy class uses composition—it creates a member instance of the principal—to expose the functionality of the principal through a set of wrapper methods or properties. The client code creates an instance of the proxy class that regulates or distributes access to the functionality of the principal.
  • 39.
    Proxy DP (Object –structural dp)
  • 40.
    Proxy DP (Object –structural dp)
  • 41.