Design Pattern lecture 3


Published on

Describe Structural Design Pattern

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Design Pattern lecture 3

  1. 1. Design PatternBy Julie IskanderMSc. Communication and Electronics
  2. 2. OutlinesLecture 3• Structural Design Patterns• Adapter• Bridge• Composite• Decorator• Façade• Proxy• Flyweight
  3. 3. Structural Patterns
  4. 4. adapter DP(Class-Structural DP)
  5. 5. adapter DP(Class-Structural DP)
  6. 6. adapter DP(Class-Structural DP)• Adapter in OO
  7. 7. adapter DP(Class-Structural DP)• What• A design that enables a noncompliant interface to be usedthrough an intermediary, which manages an adaptationprocess to effect compliance.• Where• A requirement to integrate with a noncompliant interface or arequirement for one design to leverage the functionality ofanother design.• Why• To reuse or integrate existing functionality, or adapt to changein business requirements that necessitates reengineeringdesign or functionality.• How• An intermediary class is used to map the desired functionalityfrom the source interface to that required by the target
  8. 8. adapter DP(Object-Structural DP)
  9. 9. adapter DP(Class-Structural DP)
  10. 10. adapter DP(Object-Structural DP)
  11. 11. Bridge DP(Object – Structural DP)• What• Decouple an abstraction from its implementation so thatthe two can vary independently.• Avoid a permanent binding between an abstraction andits implementation or to hide implementation from client• Why• Decoupling interface and implementation.• How• Abstraction forwards client requests to its Implementorobject.
  12. 12. Bridge DP(Object – Structural DP)
  13. 13. Bridge DP(Object – Structural DP)
  14. 14. Bridge DP(Object – Structural DP)
  15. 15. • Example• A bank Account may be a saving or a currentaccount. A bank account may also be astudent account or a child account or anormal account• Note that:• Abstract Factory can create a particularBridge• Assignment: Show how can this bedone?Bridge DP(Object – Structural DP)
  16. 16. Bridge Vs. Adapter• Bridge DP:• Meant to separate an interface from itsimplementation, to vary easily andindependently• Adapter DP:• Meant to change the interface of an existingobject• It is applied to systems after they’re designed.• Makes unrelated classes work together.
  17. 17. Composite DP(Object – Structural DP)• What• A design that ensures that an entity and a composite ofentities expose the same interface.• Where• A requirement to treat simple and composite objects alike• Why• To organize entities into hierarchies, that contain singleentities and composite entities• How• A common interface is inherited by a composite and anentity
  18. 18. Composite DP(Object – Structural DP)
  19. 19. Composite DP(Object – Structural DP)
  20. 20. A parent class shoulddefine operations thatare meaningful to allsubclassComposite DP(Object – Structural DP)
  21. 21. decorator DP(Object – Structural DP)
  22. 22. decorator DP(Object – Structural DP)
  23. 23. decorator DP(Object – Structural DP)
  24. 24. decorator DP(Object – Structural DP)
  25. 25. decorator DP(Object – Structural DP)
  26. 26. decorator DP(Object – Structural DP)• What• Attach additional responsibilities to an objectdynamically.• 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. 27. decorator DP(Object – Structural DP)
  28. 28. decorator DP(Object – Structural DP)
  29. 29. decorator DP(Object – Structural DP)
  30. 30. decorator DP(Object – Structural DP)
  31. 31. decorator DP(Object – Structural DP)
  32. 32. decorator DP(Object – Structural DP)
  33. 33. • Decorator & Adapter:• A decorator changes an object responsibilitywhile an adapter changes its interface• Decorator & Composite:• A decorator adds responsibility while acomposite is intended for object aggregationdecorator DP(Object – Structural DP)
  34. 34. Façade DP(Object – structural dp)• What• A design to hide the complexity of many interface behinda simple and uniform interface.• A requirement for a high-level abstraction that is simpleto use.• Why• Software becomes complex as it seeks to interact withmany interfaces, systems, or subsystems.• How• Managing multiple interfaces is delegated to a facadeclass that hides the complexity and presents a simpleinterface.
  35. 35. Façade DP(Object – structural dp)
  36. 36. Façade DP(Object – structural dp)
  37. 37. 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 controlaccess to it.• Where• Access needed to be regulated or access to a principal needs to bedistributed.• Why• To regulate client code access to a given resource; or for remoteaccess to functionality.• How• A proxy class is derived from the same base class as the principalclass. The proxy class uses composition—it creates a memberinstance of the principal—to expose the functionality of the principalthrough a set of wrapper methods or properties. The client codecreates an instance of the proxy class that regulates or distributesaccess to the functionality of the principal.
  38. 38. Proxy DP(Object – structural dp)
  39. 39. Proxy DP(Object – structural dp)
  40. 40. Report #2:Flyweight DPN.B. Hand Written 