Object Oriented Software  Modeling and Design  CE 350 Abdel-Karim Al-Tamimi, Ph.D. [email_address] http://faculty.yu.edu.j...
Overview <ul><li>Design Patterns </li></ul>Al-Tamimi 2011 ©
Design Patterns <ul><li>Design patterns are commonly accepted solutions to some problems that  recur  during designing dif...
Motivation for Design Patterns <ul><li>Designing reusable code is difficult </li></ul><ul><ul><li>Patterns provide reusabl...
Pros and Cons of Design Patterns <ul><li>Pros </li></ul><ul><ul><li>Design pattern provide common vocabulary </li></ul></u...
Pros and Cons of Design Patterns <ul><li>Cons </li></ul><ul><ul><li>Design patterns does not lead directly to code reuse <...
Pattern’s Four Elements <ul><li>Pattern Name </li></ul><ul><ul><li>A good name that be associated with the design framewor...
Type of Patterns <ul><li>Creational Patterns </li></ul><ul><ul><li>These patterns provide guidance on the creation of obje...
Examples of Patterns <ul><li>Creational Patterns </li></ul><ul><ul><li>Factory Pattern </li></ul></ul><ul><ul><li>Singleto...
Creational Patterns  <ul><li>Factory Pattern & Singleton Pattern  </li></ul>Al-Tamimi 2011 ©
Creational Patterns : Factory Pattern <ul><li>Problem : Creating objects (products) without specifying the exact class of ...
Factory Pattern: Example Al-Tamimi 2011 ©
Document Factory Class <ul><li>public class  DocumentFactory  { </li></ul><ul><li>… </li></ul><ul><li>public  static   Doc...
ImageReaderFactory Example <ul><li>public class  ImageReaderFactory  </li></ul><ul><li>{ </li></ul><ul><li>public static  ...
Creational Patterns: Singleton Pattern <ul><li>Problem : Needs a class that can only have one object constructed for it </...
Singleton Implementation in C# Al-Tamimi 2011 © Public class Singleton { private static readonly  Singleton _instance = ne...
Structural Patterns  <ul><li>Façade Pattern & MVC Pattern  </li></ul>Al-Tamimi 2011 ©
Structural Patterns: Façade Pattern <ul><li>Problem : How should the services be requested from a service package by clien...
Façade Pattern Al-Tamimi 2011 ©
Façade Pattern :  Example - Subsystems  <ul><li>public class  CPU </li></ul><ul><li>{ </li></ul><ul><li>public void Freeze...
Façade Pattern: Example – Façade Class <ul><li>public class  Computer </li></ul><ul><li>{ </li></ul><ul><li>CPU cpu = new ...
MVC Pattern <ul><li>Problem : How should the non-GUI classes communicate with the GUI classes </li></ul><ul><li>Solution :...
Structural Pattern: MVC Pattern <ul><li>The  model  manages the behavior and data of the application domain, </li></ul><ul...
MVC Pattern Al-Tamimi 2011 ©
MVC Pattern Communications Al-Tamimi 2011 © :Controller :Model :View 1 2 3 1 2 3 Update: Collect input data and passes the...
Behavioral Patterns  <ul><li>Observer Pattern & Chain of Responsibility Pattern  </li></ul>Al-Tamimi 2011 ©
Behavioral Patterns: Observer Pattern <ul><li>Problem : when a model object is accessed by several view objects, how shoul...
Behavioral Pattern: Observer Pattern Al-Tamimi 2011 ©
Observer Pattern: Example Al-Tamimi 2011 ©
Observer Pattern Implementation in C# <ul><li>// &quot;Subject&quot;  </li></ul><ul><li>abstract  class  Subject </li></ul...
Observer Pattern Implementation in C# <ul><li>// &quot;Observer&quot;  </li></ul><ul><li>abstract  class  Observer { </li>...
Observer Pattern Implementation in C# <ul><li>static void  Main () </li></ul><ul><li>{ </li></ul><ul><li>// Configure Obse...
Behavioral Patterns: Chain of Responsibility <ul><li>Problem : There is a potentially variable number of “processing eleme...
Behavioral Patterns: Chain of Responsibility <ul><li>Solution : Encapsulate the processing elements inside a “pipeline” ab...
Behavioral Patterns: Chain of Responsibility <ul><li>Consequences : Chain of Responsibility simplifies object interconnect...
Chain of Responsibility: Structure Al-Tamimi 2011 ©
Chain of Responsibility: Example Al-Tamimi 2011 ©
Chain of Responsibility : Implementation <ul><li>// &quot;Handler&quot;  </li></ul><ul><li>abstract class  Handler  </li><...
Chain of Responsibility : Implementation <ul><li>// &quot; ConcreteHandler1 &quot;  </li></ul><ul><li>class  ConcreteHandl...
Chain of Responsibility : Implementation <ul><li>// &quot; ConcreteHandler2 &quot;  </li></ul><ul><li>class  ConcreteHandl...
Chain of Responsibility : Implementation <ul><li>// &quot; ConcreteHandler3 &quot;  </li></ul><ul><li>class  ConcreteHandl...
Chain of Responsibility : Implementation <ul><li>static void  Main () </li></ul><ul><li>{ </li></ul><ul><li>// Setup Chain...
Pattern vs. Algorithms <ul><li>Beginners often confuses patterns and algorithms </li></ul><ul><li>Both similar since they ...
Antipattern <ul><li>If the patterns represents the best practice, anti-patterns represents lessons learned from bad design...
Resources <ul><li>http://sourcemaking.com/design_patterns </li></ul><ul><li>Chapter 8, Fundamentals of Software Engineerin...
Upcoming SlideShare
Loading in …5
×

Lecture11

1,228 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,228
On SlideShare
0
From Embeds
0
Number of Embeds
21
Actions
Shares
0
Downloads
97
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lecture11

  1. 1. Object Oriented Software Modeling and Design CE 350 Abdel-Karim Al-Tamimi, Ph.D. [email_address] http://faculty.yu.edu.jo/altamimi Al-Tamimi 2011 ©
  2. 2. Overview <ul><li>Design Patterns </li></ul>Al-Tamimi 2011 ©
  3. 3. Design Patterns <ul><li>Design patterns are commonly accepted solutions to some problems that recur during designing different applications </li></ul><ul><li>The basic idea behind patterns is that if you can master a few important patterns, you can easily spot them in application development problems and effortlessly use the pattern solution </li></ul><ul><li>Patterns can be viewed as helping designers to make certain important design decisions. At a basic level, patterns can also be viewed as well-documented building blocks for software design </li></ul><ul><li>The pattern provides an abstract description of a design problem, and how a general arrangement of elements (classes and objects in our case) solves it </li></ul><ul><li>The common definition of a pattern: “ A solution to a problem in a context ” </li></ul>Al-Tamimi 2011 ©
  4. 4. Motivation for Design Patterns <ul><li>Designing reusable code is difficult </li></ul><ul><ul><li>Patterns provide reusable frameworks </li></ul></ul><ul><ul><li>Successful reusable designs must exists </li></ul></ul><ul><li>Software components supports the reuse of code but not knowledge </li></ul><ul><ul><li>Expert knowledge are lost </li></ul></ul><ul><li>Communication of such architecture knowledge is difficult (it includes an abstract design that is a language independent) </li></ul><ul><ul><li>The purpose of the framework, and its usage </li></ul></ul><ul><ul><li>Detailed design of the framework </li></ul></ul>Al-Tamimi 2011 ©
  5. 5. Pros and Cons of Design Patterns <ul><li>Pros </li></ul><ul><ul><li>Design pattern provide common vocabulary </li></ul></ul><ul><ul><li>Design pattern help capture and spread expert knowledge </li></ul></ul><ul><ul><li>Use of design patterns helps producing code that is efficient, flexible and easily maintainable (provide a structure for change) </li></ul></ul><ul><ul><li>Improve the quality of the overall design </li></ul></ul><ul><ul><li>Improve the designer productivity </li></ul></ul>Al-Tamimi 2011 ©
  6. 6. Pros and Cons of Design Patterns <ul><li>Cons </li></ul><ul><ul><li>Design patterns does not lead directly to code reuse </li></ul></ul><ul><ul><li>At present time there are no methodology is available that can be used to select the right design pattern at the right point during the design phase </li></ul></ul><ul><ul><li>Being deceptively simple </li></ul></ul>Al-Tamimi 2011 ©
  7. 7. Pattern’s Four Elements <ul><li>Pattern Name </li></ul><ul><ul><li>A good name that be associated with the design framework (pattern) used, that also indicates the problem and its solution </li></ul></ul><ul><ul><li>Having a concise, meaningful name for a pattern improves communication among developers </li></ul></ul><ul><li>The Problem </li></ul><ul><ul><li>Describes when to apply the pattern It explains the problem and its contents and the conditions to be implemented </li></ul></ul><ul><li>The Solution </li></ul><ul><ul><li>Describes the elements that make up the design, their relationships, responsibilities, and collaborations (abstract description) </li></ul></ul><ul><li>The Consequences </li></ul><ul><ul><li>Are the results and tradeoffs of applying the pattern (space, time, system flexibility , system portability , system extensibility … ) </li></ul></ul>Al-Tamimi 2011 ©
  8. 8. Type of Patterns <ul><li>Creational Patterns </li></ul><ul><ul><li>These patterns provide guidance on the creation of objects. They help hide the details of the object instantiation from the code that uses those objects </li></ul></ul><ul><li>Structural Patterns </li></ul><ul><ul><li>Such patterns describe the organization of objects; that is, how classes and objects are composed to form larger structures </li></ul></ul><ul><li>Behavioral Patterns </li></ul><ul><ul><li>Behavioral patterns are concerned with organizing, managing and assigning responsibilities to objects during execution; that is, the focus on the patterns of communication between the objects involved during some task </li></ul></ul>Al-Tamimi 2011 ©
  9. 9. Examples of Patterns <ul><li>Creational Patterns </li></ul><ul><ul><li>Factory Pattern </li></ul></ul><ul><ul><li>Singleton Pattern </li></ul></ul><ul><li>Structural Patterns </li></ul><ul><ul><li>Façade Pattern </li></ul></ul><ul><ul><li>MVC Pattern </li></ul></ul><ul><li>Behavioral Patterns </li></ul><ul><ul><li>Observer Pattern </li></ul></ul><ul><ul><li>Chain of Responsibility Pattern </li></ul></ul>Al-Tamimi 2011 ©
  10. 10. Creational Patterns <ul><li>Factory Pattern & Singleton Pattern </li></ul>Al-Tamimi 2011 ©
  11. 11. Creational Patterns : Factory Pattern <ul><li>Problem : Creating objects (products) without specifying the exact class of object that will be created </li></ul><ul><li>Solution : Define a separate method for creating the objects, which subclasses can then override to specify the derived type of product that will be created </li></ul><ul><li>&quot;Define an interface for creating an object, but let the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses.&quot; </li></ul>Al-Tamimi 2011 ©
  12. 12. Factory Pattern: Example Al-Tamimi 2011 ©
  13. 13. Document Factory Class <ul><li>public class DocumentFactory { </li></ul><ul><li>… </li></ul><ul><li>public static Document getDocument() { </li></ul><ul><li>Document doc = null; </li></ul><ul><li>//type is loaded from properties file, or you can pass it </li></ul><ul><li>if ( DocumentType.WORD == type) { </li></ul><ul><li>doc = new WordDocument(); </li></ul><ul><li>} </li></ul><ul><li>else if (DocumentType.STAROFFICE == type) { </li></ul><ul><li>doc = new StarOfficeDocument(); </li></ul><ul><li>} </li></ul><ul><li>return doc; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 ©
  14. 14. ImageReaderFactory Example <ul><li>public class ImageReaderFactory </li></ul><ul><li>{ </li></ul><ul><li>public static ImageReader getImageReader(InputStream is) </li></ul><ul><li>{ </li></ul><ul><li>int imageType = determineImageType(is); </li></ul><ul><li>switch( imageType ) </li></ul><ul><li>{ </li></ul><ul><li>case ImageReaderFactory.GIF: </li></ul><ul><li>return new GifReader(is); </li></ul><ul><li>case ImageReaderFactory.JPEG: </li></ul><ul><li>return new JpegReader(is); </li></ul><ul><li>// etc. </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 ©
  15. 15. Creational Patterns: Singleton Pattern <ul><li>Problem : Needs a class that can only have one object constructed for it </li></ul><ul><li>Solution : the singleton pattern ensures that only one instance of a class is created. All objects that use an instance of that class use the same instance </li></ul><ul><li>This is useful when exactly one object is needed to coordinate actions across the system </li></ul><ul><li>In mathematics, a singleton is a set with exactly one element </li></ul>Al-Tamimi 2011 ©
  16. 16. Singleton Implementation in C# Al-Tamimi 2011 © Public class Singleton { private static readonly Singleton _instance = new Singleton(); private Singleton() { } public static Singleton Instance { get { return _instance; } } }
  17. 17. Structural Patterns <ul><li>Façade Pattern & MVC Pattern </li></ul>Al-Tamimi 2011 ©
  18. 18. Structural Patterns: Façade Pattern <ul><li>Problem : How should the services be requested from a service package by client classes (classes outside the package) </li></ul><ul><li>Solution : A separate class should be created to provide a common interface to their services provided by the classes in the package </li></ul>Al-Tamimi 2011 ©
  19. 19. Façade Pattern Al-Tamimi 2011 ©
  20. 20. Façade Pattern : Example - Subsystems <ul><li>public class CPU </li></ul><ul><li>{ </li></ul><ul><li>public void Freeze() { } </li></ul><ul><li>public void Jump(long addr) { } </li></ul><ul><li>public void Execute() { } </li></ul><ul><li>} </li></ul><ul><li>public class Memory </li></ul><ul><li>{ </li></ul><ul><li>public void Load(long position, byte[] data) { } </li></ul><ul><li>} </li></ul><ul><li>public class HardDrive </li></ul><ul><li>{ </li></ul><ul><li>public byte[] Read(long lba, int size) { return null; } </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 ©
  21. 21. Façade Pattern: Example – Façade Class <ul><li>public class Computer </li></ul><ul><li>{ </li></ul><ul><li>CPU cpu = new CPU(); </li></ul><ul><li>Memory memory = new Memory(); </li></ul><ul><li>HardDrive hardDrive = new HardDrive(); </li></ul><ul><li>public void StartComputer () </li></ul><ul><li>{ </li></ul><ul><li>cpu.Freeze(); </li></ul><ul><li>memory.Load(0x22, hardDrive.Read(0x66, 0x99)); </li></ul><ul><li>cpu.Jump(0x44); </li></ul><ul><li>cpu.Execute(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 ©
  22. 22. MVC Pattern <ul><li>Problem : How should the non-GUI classes communicate with the GUI classes </li></ul><ul><li>Solution : use MVC pattern to separate data domain from non-data domain modules </li></ul><ul><li>Consequences : loose coupling between view and model objects. Clear separation between the code that handles input, processes data and displays the data </li></ul>Al-Tamimi 2011 ©
  23. 23. Structural Pattern: MVC Pattern <ul><li>The model manages the behavior and data of the application domain, </li></ul><ul><ul><li>responds to requests for information about its state (usually from the view) </li></ul></ul><ul><ul><li>responds to instructions to change state (usually from the controller) </li></ul></ul><ul><li>The view renders the model into a form suitable for interaction, typically a user interface element. </li></ul><ul><ul><li>Multiple views can exist for a single model for different purposes. </li></ul></ul><ul><ul><li>A viewport typically has a one to one correspondence with a display surface and knows how to render to it </li></ul></ul><ul><li>The controller receives input and initiates a response by making calls on model objects. </li></ul><ul><ul><li>A controller accepts input from the user and instructs the model and viewport to perform actions based on that input </li></ul></ul>Al-Tamimi 2011 ©
  24. 24. MVC Pattern Al-Tamimi 2011 ©
  25. 25. MVC Pattern Communications Al-Tamimi 2011 © :Controller :Model :View 1 2 3 1 2 3 Update: Collect input data and passes them to Model object Notify: Change the model state and notify dependent Controller object Notify: Change the model state and notify dependent View object
  26. 26. Behavioral Patterns <ul><li>Observer Pattern & Chain of Responsibility Pattern </li></ul>Al-Tamimi 2011 ©
  27. 27. Behavioral Patterns: Observer Pattern <ul><li>Problem : when a model object is accessed by several view objects, how should the interactions between the model and the view objects be structured </li></ul><ul><li>Solution : observers should register themselves with the model object. All registered observers will be notified. Observer can also ask the model about specific data or status (both push and pull) </li></ul><ul><li>Consequences : decoupling between observers. Overhead on the model object. Different observers may ask for different notifications (inefficient notification) </li></ul>Al-Tamimi 2011 ©
  28. 28. Behavioral Pattern: Observer Pattern Al-Tamimi 2011 ©
  29. 29. Observer Pattern: Example Al-Tamimi 2011 ©
  30. 30. Observer Pattern Implementation in C# <ul><li>// &quot;Subject&quot; </li></ul><ul><li>abstract class Subject </li></ul><ul><li>{ </li></ul><ul><li>private ArrayList observers = new ArrayList(); </li></ul><ul><li>public void Attach (Observer observer){ </li></ul><ul><li>observers.Add(observer); </li></ul><ul><li>} </li></ul><ul><li>public void Detach (Observer observer){ </li></ul><ul><li>observers.Remove(observer); </li></ul><ul><li>} </li></ul><ul><li>public void Notify () </li></ul><ul><li>{ </li></ul><ul><li>foreach (Observer o in observers){ </li></ul><ul><li>o. Update ();} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>// &quot;ConcreteSubject&quot; </li></ul><ul><li>class ConcreteSubject:Subject { </li></ul><ul><li>public string SubjectState ; </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 © Model Object
  31. 31. Observer Pattern Implementation in C# <ul><li>// &quot;Observer&quot; </li></ul><ul><li>abstract class Observer { </li></ul><ul><li>public abstract void Update (); </li></ul><ul><li>} </li></ul><ul><li>// &quot;ConcreteObserver&quot; </li></ul><ul><li>class ConcreteObserver : Observer </li></ul><ul><li>{ </li></ul><ul><li>private string name; </li></ul><ul><li>private string observerState; </li></ul><ul><li>private ConcreteSubject subject; </li></ul><ul><li>// Constructor </li></ul><ul><li>public ConcreteObserver (ConcreteSubject subject, string name){ </li></ul><ul><li>this.subject = subject; </li></ul><ul><li>this.name = name; </li></ul><ul><li>} </li></ul><ul><li>public override void Update (){ </li></ul><ul><li>observerState = subject.SubjectState; </li></ul><ul><li>Console.WriteLine(&quot;Observer {0}'s new state is {1}&quot;, </li></ul><ul><li>name, observerState); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 © Observer Object
  32. 32. Observer Pattern Implementation in C# <ul><li>static void Main () </li></ul><ul><li>{ </li></ul><ul><li>// Configure Observer pattern </li></ul><ul><li>ConcreteSubject s = new ConcreteSubject(); </li></ul><ul><li>s. Attach (new ConcreteObserver(s,&quot;X&quot;)); </li></ul><ul><li>s. Attach (new ConcreteObserver(s,&quot;Y&quot;)); </li></ul><ul><li>s. Attach (new ConcreteObserver(s,&quot;Z&quot;)); </li></ul><ul><li>// Change subject and notify observers </li></ul><ul><li>s.SubjectState = &quot;ABC&quot;; </li></ul><ul><li>s. Notify (); </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 © Using Observer Pattern
  33. 33. Behavioral Patterns: Chain of Responsibility <ul><li>Problem : There is a potentially variable number of “processing element” and a stream of requests that must be handled. Need to efficiently process the requests </li></ul>Al-Tamimi 2011 ©
  34. 34. Behavioral Patterns: Chain of Responsibility <ul><li>Solution : Encapsulate the processing elements inside a “pipeline” abstraction; and have clients “launch and leave” their requests at the entrance to the pipeline </li></ul>Al-Tamimi 2011 ©
  35. 35. Behavioral Patterns: Chain of Responsibility <ul><li>Consequences : Chain of Responsibility simplifies object interconnections. Instead of senders and receivers maintaining references to all candidate receivers, each sender keeps a single reference to the head of the chain, and each receiver keeps a single reference to its immediate successor in the chain. The number and type of handler objects isn’t known a priori, they can be configured dynamically </li></ul>Al-Tamimi 2011 ©
  36. 36. Chain of Responsibility: Structure Al-Tamimi 2011 ©
  37. 37. Chain of Responsibility: Example Al-Tamimi 2011 ©
  38. 38. Chain of Responsibility : Implementation <ul><li>// &quot;Handler&quot; </li></ul><ul><li>abstract class Handler </li></ul><ul><li>{ </li></ul><ul><li>protected Handler successor ; </li></ul><ul><li>public void SetSuccessor (Handler successor) </li></ul><ul><li>{ </li></ul><ul><li>this.successor = successor; </li></ul><ul><li>} </li></ul><ul><li>public abstract void HandleRequest (int request); </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 © Handler (abstract)
  39. 39. Chain of Responsibility : Implementation <ul><li>// &quot; ConcreteHandler1 &quot; </li></ul><ul><li>class ConcreteHandler1 : Handler </li></ul><ul><li>{ </li></ul><ul><li>public override void HandleRequest (int request) </li></ul><ul><li>{ </li></ul><ul><li>if (request >= 0 && request < 10) </li></ul><ul><li>{ </li></ul><ul><li>Console.WriteLine(&quot;{0} handled request {1}&quot;, </li></ul><ul><li>this.GetType().Name, request); </li></ul><ul><li>} </li></ul><ul><li>else if (successor != null) </li></ul><ul><li>{ </li></ul><ul><li>successor.HandleRequest(request) ; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 © Handler 1
  40. 40. Chain of Responsibility : Implementation <ul><li>// &quot; ConcreteHandler2 &quot; </li></ul><ul><li>class ConcreteHandler2 : Handler </li></ul><ul><li>{ </li></ul><ul><li>public override void HandleRequest (int request) </li></ul><ul><li>{ </li></ul><ul><li>if (request >= 10 && request < 20) </li></ul><ul><li>{ </li></ul><ul><li>Console.WriteLine(&quot;{0} handled request {1}&quot;, </li></ul><ul><li>this.GetType().Name, request); </li></ul><ul><li>} </li></ul><ul><li>else if (successor != null) </li></ul><ul><li>{ </li></ul><ul><li>successor.HandleRequest(request); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 © Handler 2
  41. 41. Chain of Responsibility : Implementation <ul><li>// &quot; ConcreteHandler3 &quot; </li></ul><ul><li>class ConcreteHandler3 : Handler </li></ul><ul><li>{ </li></ul><ul><li>public override void HandleRequest (int request) </li></ul><ul><li>{ </li></ul><ul><li>if (request >= 20 && request < 30) </li></ul><ul><li>{ </li></ul><ul><li>Console.WriteLine(&quot;{0} handled request {1}&quot;, </li></ul><ul><li>this.GetType().Name, request); </li></ul><ul><li>} </li></ul><ul><li>else if (successor != null) </li></ul><ul><li>{ </li></ul><ul><li>successor.HandleRequest(request); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 © Handler 3
  42. 42. Chain of Responsibility : Implementation <ul><li>static void Main () </li></ul><ul><li>{ </li></ul><ul><li>// Setup Chain of Responsibility </li></ul><ul><li>Handler h1 = new ConcreteHandler1(); </li></ul><ul><li>Handler h2 = new ConcreteHandler2(); </li></ul><ul><li>Handler h3 = new ConcreteHandler3(); </li></ul><ul><li>h1.SetSuccessor(h2); </li></ul><ul><li>h2.SetSuccessor(h3); </li></ul><ul><li>// Generate and process request </li></ul><ul><li>int[] requests = {2, 5, 14, 22, 18, 3, 27, 20}; </li></ul><ul><li>foreach (int request in requests) </li></ul><ul><li>{ </li></ul><ul><li>h1.HandleRequest(request); </li></ul><ul><li>} </li></ul><ul><li>// Wait for user </li></ul><ul><li>Console.Read(); </li></ul><ul><li>} </li></ul>Al-Tamimi 2011 © Using CoR
  43. 43. Pattern vs. Algorithms <ul><li>Beginners often confuses patterns and algorithms </li></ul><ul><li>Both similar since they provide reusable solutions </li></ul><ul><li>Algorithms : solving problems with reduced space and/or time requirements </li></ul><ul><li>Patterns : focuses on understandability and maintainability of the design and on easier development </li></ul>Al-Tamimi 2011 ©
  44. 44. Antipattern <ul><li>If the patterns represents the best practice, anti-patterns represents lessons learned from bad designs </li></ul><ul><ul><li>Those that describe bad solutions to problems which leads to bad situations </li></ul></ul><ul><ul><li>Those that describe how to avoid bad solutions to problems </li></ul></ul><ul><li>Very important to know what to avoid in your design phase/solving a problem </li></ul>Al-Tamimi 2011 ©
  45. 45. Resources <ul><li>http://sourcemaking.com/design_patterns </li></ul><ul><li>Chapter 8, Fundamentals of Software Engineering by Rajib Mall </li></ul><ul><li>Object Oriented Thought Process </li></ul><ul><li>Guide to Unified Process Featuring UML, JAVA and Design Patterns </li></ul><ul><li>http://en.wikipedia.org/ [for each pattern] </li></ul>Al-Tamimi 2011 ©

×