201006 its tutorial

1,243 views

Published on

This tutorial will discuss key software architecture concepts allowing researchers and practitioners to move from software development as a one-ofa-kind endeavor to software development as a system of modules that can be widely used in highly adaptable ways. Participants will understand how the use of software architecture models avoids difficulty by providing robust and flexible systems, applies well-established methodologies, improves user experience and, warrants that the final product satisfies all the requirements (functional and non functional). The attendees will better understand how to apply software patterns as part of their software development methodology. They will engage in exercises that apply software patterns at architectural and design levels to create an Intelligent Tutor System (ITS) with an associated widespread use of components. And, understand how software architecture can improve ITS development to a point where one could be sure that the product would work, as planned, in uncontrolled and non-standardized environments and be able to be incrementally improved to be adapted with new technologies. The attendee will become familiar with the standard vocabularies of patterns in order to apply it as a way of shared communication inside the team and outside with the experts and consultants. This will improve attendees’ abilities to express and transfer knowledge that can enrich the development and improvement of systems.

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

  • Be the first to like this

No Downloads
Views
Total views
1,243
On SlideShare
0
From Embeds
0
Number of Embeds
137
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

201006 its tutorial

  1. 1. Javier Gonzalez Sanchez javiergs@asu.edu Maria Elena Chavez Echeagaray helenchavez@asu.edu
  2. 2. Agenda our goals for today 1.  Presentation 2.  Software Architecture 3.  Patterns 4.  Developing Tutoring Systems 5.  Conclusion
  3. 3. 1. Presentation About You, Us, and The Tutorial
  4. 4. About You who are you and why are you here today… academia | client   What did you expect to learn today? developer engineer manager   Which is your profile? Intelligent Tutoring Systems Conference 2010 5
  5. 5. About You what about your background Intelligent Tutoring Systems Conference 2010 6
  6. 6. About the Tutorial what is this tutorial about … Software Architecture Patterns ITS Intelligent Tutoring Systems Conference 2010 8
  7. 7. About the Tutorial what do you know about this…   Software Architecture   Software Engineering   Object-Oriented Paradigm   Component   Reuse   Patterns (design, architecture, code)   Model-driven and Reuse-driven Architecture Intelligent Tutoring Systems Conference 2010 9
  8. 8. About the Tutorial Motivation Needs Requirements Product Intelligent Tutoring Systems Conference 2010 10
  9. 9. About the Tutorial Motivation Components   maintenance,   escalability, Patterns   modularity,   performance.   This is NOT only about programming. Intelligent Tutoring Systems Conference 2010 11
  10. 10. 2. Software Architecture Concepts
  11. 11. Topics 2.1. Software Architecture 2.2. Identifying Components 2.3. Identifying Relations 2.4. Software Patterns 2.5. About Software Engineering Intelligent Tutoring Systems Conference 2010 13
  12. 12. 2.1. Software Architecture Architectures and Architectural Styles
  13. 13. Architecture This is about components and relationships Maya o Aztec? huge and extravagant, great to the view. Impressive and detailed roofs. Columns China Doric, Jonic, and Rocs, Corintian Wood in the inner structure and colored windows. Fire, Power and Beauty. Gothic more details and elaboration. Satisfy the goods and self (symetric and nature). Piramids in the rights angle and stone columns. clasic Egypt Intelligent Tutoring Systems Conference 2010 15
  14. 14. Software Architecture A big scenario Intelligent Tutoring Systems Conference 2010 16
  15. 15. Software Architecture A small scenario Intelligent Tutoring Systems Conference 2010 17
  16. 16. Software Architecture Buliding houses One person task Simple structure Team task Simple process Requires a model Simple tools Has well-defined processes Limited teorethical knowledge Requires powerful tools As the system gets bigger, the algorithms and the data structures are not the main problem any more. Intelligent Tutoring Systems Conference 2010 18
  17. 17. Key Questions Answers What Why System Architectural qualities satisfy characteristics architecture requirements limits Architectural Representation System qualities produce technology define Who How follow architect process knowledge Define organization clients rolls Intelligent Tutoring Systems Conference 2010 19
  18. 18. The Architect Role   Must obtain information about the problem and design a solution which satisfies the requirements, both functionals and non functionals.   Must use and apply patterns, models and frameworks.   Must actively participate on the development but not as a developer.   Must generate the guidelines that has to be considered in the creation of prouduct’s families. Intelligent Tutoring Systems Conference 2010 20
  19. 19. Summary Define each concept Physical Applied or business Data Class or type Architectural styles Architecture Component Pattern Rules Intelligent Tutoring Systems Conference 2010 21
  20. 20. 2. Identifying Components
  21. 21. From the storyboard to the code list Classes treasury Methods Variables Relations professor Complexity Time Cost student group Intelligent Tutoring Systems Conference 2010 23
  22. 22. From the storyboard to the code   A professor could study in the school (in other words he could be a student).   At the university exists a treasury building where all the paymets are gathered.   A group is a set of students that get the same treatment.   Each professor has a list where register students’ attendance and grades.   When a student do not pay his monthly fees he is removed from the group. Intelligent Tutoring Systems Conference 2010 24
  23. 23. LEGO model “Creativity” is positive … … components Intelligent Tutoring Systems Conference 2010 25
  24. 24. 2.3 Identifying Relations
  25. 25. Speaking about relations a)  Be a)  I observe to … b)  Use b)  I am a face of … c)  Has c)  I am a decoration of… d)  I am unique… e)  I build a … f)  I work with … g)  I am part of … Intelligent Tutoring Systems Conference 2010 27
  26. 26. Observer Intelligent Tutoring Systems Conference 2010 28
  27. 27. Facade Intelligent Tutoring Systems Conference 2010 29
  28. 28. Decorator Intelligent Tutoring Systems Conference 2010 30
  29. 29. Builder Intelligent Tutoring Systems Conference 2010 31
  30. 30. Strategy Intelligent Tutoring Systems Conference 2010 32
  31. 31. Composite Intelligent Tutoring Systems Conference 2010 33
  32. 32. Memento Intelligent Tutoring Systems Conference 2010 34
  33. 33. Chain of responsability Intelligent Tutoring Systems Conference 2010 35
  34. 34. LEGO model a)  Relations b)  Hierarchical components c)  Autonomy d)  Standard e)  The “change” is my friend f)  Creativity g)  Predictable product Intelligent Tutoring Systems Conference 2010 36
  35. 35. 2.4 Software Patterns
  36. 36. Description   Patterns are general solutions to frequent and repeated well-known problems. They will not solve a specific problem, but they provide sort of template that may be reused in order to speed up the development process.   Design patterns (Gang of Four - GoF) – Erich Gamma, Richard Helm, Ralph Johnson y John Vlisides :: 1990 Intelligent Tutoring Systems Conference 2010 38
  37. 37. The REAL Life Intelligent Tutoring Systems Conference 2010 39
  38. 38. Advantages   Formalize a common vocabulary.   Standardize the way in which a design is defined.   Use prior knowledge to make easier the learning process. Intelligent Tutoring Systems Conference 2010 40
  39. 39. Example in Design Problem: Restrict the instantiation of a class to one object. Problem: Example of a Logger Solution : Warranties that one class has only one instance and gives a global point of access to that class. Pattern : Singleton Intelligent Tutoring Systems Conference 2010 41
  40. 40. Example in Code public class Treasury { private static Treasury TREASURY = null; private Treasury () { } public static Treasury getTreasury() { if (TREASURY == null) TREASURY = new Treasury(); return TREASURY; } // The rest of the class goes in here } Intelligent Tutoring Systems Conference 2010 42
  41. 41. And more … composition decorator observer factory strategy singleton decorator Intelligent Tutoring Systems Conference 2010 43
  42. 42. UML Elements Intelligent Tutoring Systems Conference 2010 44
  43. 43. 2.5 About Software Engineering
  44. 44. OOSE UML Build models that represents Each model is reviewed and the system manipulated by a group of stakeholders. Objects, types and classes Code Change Systemic informal model Real system problem OO-SE complex Requirements – Analysis – Design - Implementation -- Testing abstract - iterations - concrete Intelligent Tutoring Systems Conference 2010 46
  45. 45. Fundamentals Needs Notation requirements models Process (diagrams) methodology Tools Product Intelligent Tutoring Systems Conference 2010 47
  46. 46. Methodology Intelligent Tutoring Systems Conference 2010 48
  47. 47. Software Qualities Static: Modificable, Portable, Reusable, Integrable, Verificable. Dynamic: Performance, Disponibility, Funcionality, Usability. Architectural: Conceptual Integrity, Correctness, Completeness, Economic Feasibility Intelligent Tutoring Systems Conference 2010 49
  48. 48. Questions Intelligent Tutoring Systems Conference 2010 50
  49. 49. Exercise How many members on the team? How much time? ITS for How many classes or arithmetic modules? How many LOC? Intelligent Tutoring Systems Conference 2010 51
  50. 50. Exam   What is the difference between architecture and system?   What is the difference between a component and a module?   What is the difference between a pattern and a rule?   What is the difference between a model and an abstraction? Intelligent Tutoring Systems Conference 2010 52
  51. 51. 3. Patterns
  52. 52. Topics 1.  Principles of software patterns 2.  Creation of objects with patterns 3.  Behavior of objects with patterns 4.  Structure of objects with patterns 5.  Patterns of patterns 6.  Exercise 7.  Anti-patterns 8.  Idioms Intelligent Tutoring Systems Conference 2010 54
  53. 53. 3. 1 Principles of Patterns
  54. 54. Context ANALYSTS AND DESIGNERS PROGRAMMERS Intelligent Tutoring Systems Conference 2010 56
  55. 55. Classification ANTI - PATTERNS •  Java Code •  .Net •  PHP •  Creation Design •  Structure •  Behavior Architecture Testings PATTERNS Project Management Intelligent Tutoring Systems Conference 2010 57
  56. 56. Design Patterns Creation Behavior Structure •  Abstract Factory •  Chain of Responsabilities •  Adapter •  Factory Method •  Observer •  Bridge •  Builder •  Strategy •  Composite •  Prototype (Clonable) •  Visitor •  Decorator •  Singleton •  Memento •  Facade Intelligent Tutoring Systems Conference 2010 58
  57. 57. 3. A Quick Summary of Patterns Our rules
  58. 58. Design Patterns   One to many dependency among objects.   The change of state of one object is notified to N objects.   Frequently used Intelligent Tutoring Systems Conference 2010 60
  59. 59. Observer Pattern abstract  class  Subject  {      private  ArrayList  observers=new  ArrayList ();   class  ConcreteSubject  :  Subject  {      public  void  Attach(  Observer  observer  )  {          observers.Add(  observer  );      private  string  subjectState;      }      get{  return  subjectState;  }      public  void  Detach(  Observer  observer  )  {      set{  subjectState  =  value;  }          observers.Remove(  observer  );   }      }      public  void  Notify()  {          foreach(  Observer  o  in  observers  )          o.Update();      }   }  
  60. 60. Observer Pattern abstract  class  Observer  {      abstract  public  void  Update();   }   class  ConcreteObserver  :  Observer  {      private  string  name;      private  string  observerState;      private  ConcreteSubject  subject        public  ConcreteObserver(  ConcreteSubject  s,  string  n  )  {          this.subject  =  s;          this.name  =  n;      }      override  public  void  Update(){    observerState  =  subject.SubjectState;    Console.WriteLine              ("Observer  {0}'s  new  state  is  {1}",name,observerState  );        }    get  {  return  subject;  }   set  {  subject  =  value;  }   }   Intelligent Tutoring Systems Conference 2010 62
  61. 61. Observer pattern public  static  void  main(  string[]  args){      ConcreteSubject  s  =  new  ConcreteSubject();      s.Attach(  new  ConcreteObserver(  s,  "X"  )  );      s.Attach(  new  ConcreteObserver(  s,  "Y"  )  );      s.Attach(  new  ConcreteObserver(  s,  "Z"  )  );      s.SubjectState  =  "ABC";      s.Notify();   }   Intelligent Tutoring Systems Conference 2010 63
  62. 62. Activity Group 1 Treasury Only one at campus If the student pays he is enrolled to the group If the student withdraw a course does not appear in the list Intelligent Tutoring Systems Conference 2010 64
  63. 63. Singleton pattern   Assure only one instance of a class and the access to it.   One class assure the creation and maintenance of only one instance of itself.   Frequently used. Intelligent Tutoring Systems Conference 2010 65
  64. 64. Singleton pattern class  Singleton  {        private  static  Singleton  instance;   protected  Singleton()  {}      public  static  Singleton  Instance()  {          if(  instance  ==  null  )              instance  =  new  Singleton();          return  instance;          }   }   public  class  Client  {          public  static  void  main  ()  {                  //  Constructor  is  protected  –  no  puedo  usar  new!!      Singleton  s1  =  Singleton.Instance();                  Singleton  s2  =  Singleton.Instance();      if  (  s1  ==  s2  )              Console.WriteLine(  “it  is  itself"  );          }   }     Intelligent Tutoring Systems Conference 2010 66
  65. 65. Facade pattern   Provide a unique interface for a set of interfaces Intelligent Tutoring Systems Conference 2010 67
  66. 66. Facade pattern class  SistemaUno  {        public  void  accionUno()  {   System.out.println(“  Trabajando  Uno");        }   }   class  SistemaDos  {        public  void  accionDos()  {    System.out.println(“Trabajando  Dos");        }   }   class  SistemaTres{      public  void  accionTres(){      System.out.println(“Trabajando  Tres");      }   }   Intelligent Tutoring Systems Conference 2010 68
  67. 67. Facade pattern class  Facade  {   public  class  Client  {          SistemaUno  one;          SistemaDos  two;          public  static  void  main(string[]  args)  {          SistemaTres  three;                  Facade  f  =  new  Facade();                  f.metodo();          public  Facade()  {          }                  one  =  new  SistemaUno();   }                    two  =  new  SistemaDos();                  three  =  new  SistemaTres();   }    Trabajando:          public  void  metodo()  {    Trabajando  Uno                System.out.println  (  “Trabajando:  "  );    Trabajando  Dos                one.accionUno();    Trabajando  Tres                two.accionDos();    }   }  
  68. 68. Group 1 Treasury Only one at campus If the student pays he is enrolled to the group If the student withdraw a course does not appear in the list Intelligent Tutoring Systems Conference 2010 70
  69. 69. Activity Group 1 Attendance Grade list list Intelligent Tutoring Systems Conference 2010 71
  70. 70. Decorator pattern   Dynamically adds responsabilities to an object Intelligent Tutoring Systems Conference 2010 72
  71. 71. Decorator pattern //elements  to  which  will  add  responsabilities   abstract  class  Component  {          abstract  public  void  Operation();   }   class  ConcreteComponent  implements  Component  {          public  void  Operation()  {          System.out.println(“operación  base");          }   }   Intelligent Tutoring Systems Conference 2010 73
  72. 72. Decorator pattern //  decorador   abstract  class  Decorator  implements  Component  {          protected  Component  component;          public  void  SetComponent(  Component  component  )  {                  this.component  =  component;          }          public  void  Operation()  {                  if(  component  !=  null  )      component.Operation();          }   }   class  ConcreteDecoratorA  implements  Decorator  {          private  string  addedState;          public  void  Operation()  {                super.Operation();    addedState  =  "new  state";    System.out.print(“operación  del  decorador  A");          }   }   Intelligent Tutoring Systems Conference 2010 74
  73. 73. Decorator pattern class  ConcreteDecoratorB  implements  Decorator  {          public  void  Operation()  {                  super.Operation();        AddedBehavior();        System.out.println  (“operación  del  decorador  B");          }          void  AddedBehavior()  {    …  }   }   public  class  Client  {        public  static  void  Main(  string[]  args  )  {              ConcreteComponent  c  =  new  ConcreteComponent();   ConcreteDecoratorA  d1  =  new  ConcreteDecoratorA();   ConcreteDecoratorB  d2  =  new  ConcreteDecoratorB();   d1.SetComponent(  c  );   d2.SetComponent(  d1  );   d2.Operation();          }   }  
  74. 74. Activity Group 1 Attendance Grade List List Intelligent Tutoring Systems Conference 2010 76
  75. 75. scenary University Registrar Human Resources Treasury Group 1 Attendance Grade List List Intelligent Tutoring Systems Conference 2010 77
  76. 76. Builder pattern   Slipt the construction of an complex object from its representation. The same process of contruction could create different representations. Intelligent Tutoring Systems Conference 2010 78
  77. 77. Builder pattern class  Director  {   class  ConcreteBuilder1  extends  Builder  {          public  void  Construct(  Builder  builder  )  {          private  Product  product;                  builder.BuildPartA();          public  void  BuildPartA()  {                  builder.BuildPartB();                  product  =  new  Product();          }                  product.Add(  "PartA"  );   }          }          public  void  BuildPartB()  {                  product.Add(  "PartB"  );   abstract  class  Builder  {          }          public  Product  GetResult()  {          public  void  BuildPartA();                  return  product;          public  void  BuildPartB();          }          public  Product  GetResult();   }   }  
  78. 78. Builder pattern class  ConcreteBuilder2  extends  Builder  {   class  Product  {          private  Product  product;          ArrayList  parts  =  new  ArrayList();          public  void  BuildPartA()  {                    product  =  new  Product();          public  void  Add(  string  part  )  {        product.Add(  "PartX"  );                  parts.Add(  part  );          }          }          public  void  BuildPartB()  {          public  void  Show()  {                  product.Add(  "PartY"  );                  System.out.prinltln  (  “Partes  del          }   Producto"  );                  foreach(  string  part  in  parts  )          public  Product  GetResult()  {                          System.out.prinltln(  part  );                  return  product;          }          }   }   }  
  79. 79. Builder pattern public  class  Client  {          public  static  void  main(  string[]  args  )  {                  Director  director  =  new  Director(  );                  Builder  b1  =  new  ConcreteBuilder1();                  Builder  b2  =  new  ConcreteBuilder2();                  director.Construct(  b1  );                  Product  p1  =  b1.GetResult();                  p1.Show();                  director.Construct(  b2  );      Product  p2  =  b2.GetResult();      p2.Show();          }   }   Intelligent Tutoring Systems Conference 2010 81
  80. 80. Activity University Registrar Human Resources Treasury Group 1 Attendance Grade List List Intelligent Tutoring Systems Conference 2010 82
  81. 81. 3.2. Design patterns creation of objects:: the goal “low coupling”
  82. 82. Abstract Factory   Gang of Four (GoF).   Creation of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Abstract Factory is a class that creates instances of several classes’ families.   Creates instances of a class when it is selected on execution-time. Patrones de Codificación Intelligent Tutoring Systems Conference 2010 84
  83. 83. Abstract Factory class  Main  {   abstract  class  AbstractFactory  {      public  static  void  Main()  {      public  abstract  AbstractProductA  CreateProductA();          AbstractFactory  f1  =  new  ConcreteFactory1();      public  abstract  AbstractProductB  CreateProductB();          Client  c1  =  new  Client(f1);   }          client1.Run();          AbstractFactory  f2  =  new  ConcreteFactory2();   class  ConcreteFactory1  :  AbstractFactory  {          Client  c2  =  new  Client(f2);      public  override  AbstractProductA  CreateProductA()  {          client2.Run();          return  new  ProductA1();      }      }   }      public  override  AbstractProductB  CreateProductB()  {          return  new  ProductB1();   class  Client  {      }      private  AbstractProductA  _abstractProductA;   }      private  AbstractProductB  _abstractProductB;      public  Client(AbstractFactory  f)  {   class  ConcreteFactory2  :  AbstractFactory  {          _abstractProductB  =  f.CreateProductB();      public  override  AbstractProductA  CreateProductA()  {          return  new  ProductA2();          _abstractProductA  =  f.CreateProductA();      }      }      public  override  AbstractProductB  CreateProductB()  {      public  void  Run()  {          return  new  ProductB2();      _abstractProductB.Interact(_abstractProductA);      }      }   }   }  
  84. 84. Abstract Factory abstract  class  AbstractProductA  {   class  ProductA1  :  AbstractProductA  {     }   }   abstract  class  AbstractProductB  {     class  ProductB1  :  AbstractProductB  {        public  abstract  void  Interact(AbstractProductA  a);        public  override  void  Interact(AbstractProductA  a)  {   }          //  action      }   }   class  ProductA2  :  AbstractProductA  {   }   class  ProductB2  :  AbstractProductB  {      public  override  void  Interact(AbstractProductA  a)  {          //  action      }   }  
  85. 85. From cartoons to CODE singleton Classes Methods university student treasury Variables observer Relations Complexity observer subject professor Time Cost list group Intelligent Tutoring Systems Conference 2010 87
  86. 86. Abstract Factory factory university HR registrar product person Patrones de Codificación professor student Intelligent Tutoring Systems Conference 2010 88
  87. 87. Factory Method   GoF.   Creation of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Factory is a class that creates instances of several derivated classes.   It resolves the problem of creating objects with out specifying their exact class, but Patrones de only their superclass.. Codificación   A PRODUCT Intelligent Tutoring Systems Conference 2010 89
  88. 88. Factory Method class  Main  {   abstract  class  Creator  {              Creator[]  creators  =  new  Creator[2];      public  abstract  Product  FactoryMethod();              creators[0]  =  new  ConcreteCreatorA();   }              creators[1]  =  new  ConcreteCreatorB();   class  ConcreteCreatorA  :  Creator  {              foreach  (Creator  creator  in  creators)      {      public  override  Product  FactoryMethod()  {                  Product  product  =  creator.FactoryMethod();          return  new  ConcreteProductA();              }      }   }   }   class  ConcreteCreatorB  :  Creator  {   abstract  class  Product  {      public  override  Product  FactoryMethod()  {   }          return  new  ConcreteProductB();      }   class  ConcreteProductA  :  Product    {   }   }   class  ConcreteProductB  :  Product  {   }  
  89. 89. Factory Method creator registrar product list Intelligent Tutoring Systems Conference 2010 91
  90. 90. Builder   GoF.   Creation of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Builder separates the building of an object from its representation.   Creates a complex object by following a set of steps. Patrones de Codificación Intelligent Tutoring Systems Conference 2010 92
  91. 91. Builder public  class  MainApp  {   abstract  class  Builder  {      public  static  void  Main()  {      public  abstract  void  BuildPartA();          Director  director  =  new  Director();      public  abstract  void  BuildPartB();      public  abstract  Product  GetResult();          Builder  b1  =  new  ConcreteBuilder1();   }          Builder  b2  =  new  ConcreteBuilder2();          director.Construct(b1);   class  ConcreteBuilder1  :  Builder  {          Product  p1  =  b1.GetResult();      private  Product  _product  =  new  Product();          p1.Show();      public  override  void  BuildPartA()  {          director.Construct(b2);          _product.Add("PartA");      }          Product  p2  =  b2.GetResult();      public  override  void  BuildPartB()  {          p2.Show();          _product.Add("PartB");      }      }   }      public  override  Product  GetResult()  {          return  _product;   class  Director  {      }   }      public  void  Construct(Builder  builder)  {          builder.BuildPartA();          builder.BuildPartB();      }   }  
  92. 92. Builder class  ConcreteBuilder2  :  Builder  {   class  Product  {      private  Product  _product  =  new  Product();      private  List<string>  _parts  =  new  List<string>();      public  override  void  BuildPartA()  {      public  void  Add(string  part)  {          _parts.Add(part);          _product.Add("PartX");      }      }      public  void  Show()  {      public  override  void  BuildPartB()  {          printf("nProduct  Parts  -­‐-­‐-­‐-­‐-­‐-­‐-­‐");          _product.Add("PartY");          foreach  (string  part  in  _parts)      }              printf(part);      public  override  Product  GetResult()  {      }   }          return  _product;      }   }  
  93. 93. Builder builder university group registrar Product professor student person Intelligent Tutoring Systems Conference 2010 95
  94. 94. Prototype   GoF.   Creation of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Prototype specifies the objects to be created using as a guide an instance that become the prototype. The new instances are created by copying the original one. Patrones de Codificación Intelligent Tutoring Systems Conference 2010 96
  95. 95. Prototype | Clonable class  MainApp  {   class  ConcretePrototype1  :  Prototype  {      static  void  Main()  {      public  ConcretePrototype1(string  id)  :  base(id)  {          CPrototype1  p1  =  new  CPrototype1("I");      }      public  override  Prototype  Clone()  {          CPrototype1  c1  =  (CPrototype1)p1.Clone();          return  (Prototype)this.MemberwiseClone();          CPrototype2  p2  =  new  CPrototype2("II");      }          CPrototype2  c2  =  (CPrototype2)p2.Clone();   }      }   }   class  ConcretePrototype2  :  Prototype  {      public  ConcretePrototype2(string  id)  :  base(id)  {      }   abstract  class  Prototype  {      public  override  Prototype  Clone()  {      private  string  _id;            return  (Prototype)this.MemberwiseClone();      public  Prototype(string  id)  {      }          this._id  =  id;   }      }      public  string  Id{      }      get  {  return  _id;  }      }      public  abstract  Prototype  Clone();   }  
  96. 96. Prototype | Clonable cloneable registrar group Intelligent Tutoring Systems Conference 2010 98
  97. 97. 3.3. Design Patterns object behavior:: the goal “low coupling”.
  98. 98. Chain of Responsability   GoF.   Behavior of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Routes a request through a serie of handlers. Each handler decides either to process or not the request. If a handler attend the request, the process finish. Patrones de Codificación Intelligent Tutoring Systems Conference 2010 100
  99. 99. Chain of Responsability class  ConcreteHandler1  :  Handler  {   class  MainApp  {      public  override  void  HandleRequest(int  request)  {      static  void  Main()  {          if  (request  >=  0  &&  request  <  10)  {      //  acción          Handler  h1  =  new  ConcreteHandler1();          }  else  if  (successor  !=  null)  {          Handler  h2  =  new  ConcreteHandler2();              successor.HandleRequest(request);          Handler  h3  =  new  ConcreteHandler3();          }      }          h1.SetSuccessor(h2);   }          h2.SetSuccessor(h3);          int[]  requests  =  {  2,  5,  14,  22,  18,  3,  27,  20  };   class  ConcreteHandler2  :  Handler  {          foreach  (int  request  in  requests)  {      public  override  void  HandleRequest(int  request)  {              h1.HandleRequest(request);          if  (request  >=  10  &&  request  <  20)  {      //  acción          }  else  if  (successor  !=  null)  {          }              successor.HandleRequest(request);      }          }   }      }   }   abstract  class  Handler  {      protected  Handler  successor;   class  ConcreteHandler3  :  Handler  {      public  override  void  HandleRequest(int  request)  {      public  void  SetSuccessor(Handler  successor)  {          if  (request  >=  20  &&  request  <  30)  {      //  acción          this.successor  =  successor;          }  else  if  (successor  !=  null)  {      }              successor.HandleRequest(request);}      public  abstract  void  HandleRequest(int  request);          }   }      }   }  
  100. 100. Chain of Responsability
  101. 101. Strategy   GoF.   Behavior of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Extracts the complex algorithms of individual classes in such a way that they could be easily replaced. Intelligent Tutoring Systems Conference 2010 103
  102. 102. Strategy abstract  class  Strategy  {   class  MainApp  {      public  abstract  void  AlgorithmInterface();      static  void  Main()  {   }          Context  context;          context  =  new  Context(new  CStrategyA());   class  CStrategyA  :  Strategy  {          context.ContextInterface();      public  override  void  AlgorithmInterface()  {      //          context  =  new  Context(new  CStrategyB());      }          context.ContextInterface();   }          context  =  new  Context(new  CStrategyC());          context.ContextInterface();   class  CStrategyB  :  Strategy  {      }      public  override  void  AlgorithmInterface()  {      //   }        }   }   class  Context  {      private  Strategy  _strategy;   class  CStrategyC  :  Strategy  {      public  Context(Strategy  strategy)  {      public  override  void  AlgorithmInterface()  {          this._strategy  =  strategy;      //      }      }   }      public  void  ContextInterface()  {          _strategy.AlgorithmInterface();      }   }  
  103. 103. Strategy printer list Intelligent Tutoring Systems Conference 2010 105
  104. 104. Visitor   GoF.   Behavior of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Defines a new operation in a class with out modifying it. Intelligent Tutoring Systems Conference 2010 106
  105. 105. Visitor class  ConcreteVisitor1  :  Visitor  {   class  MainApp  {      public  override  void  VCElementA(CElementA  cea)  {      static  void  Main()  {          //  accion          ObjectStructure  o  =  new  ObjectStructure();      }          o.Attach(new  ConcreteElementA());      public  override  void  VCElementB(CElementB  ceb)  {          o.Attach(new  ConcreteElementB());          //  accion        }          ConcreteVisitor1  v1  =  new  ConcreteVisitor1();   }          ConcreteVisitor2  v2  =  new  ConcreteVisitor2();          o.Accept(v1);   class  ConcreteVisitor2:  Visitor  {          o.Accept(v2);        public  override  void  VCElementA(CElementA  cea)  {      }          //  accion      }   }      public  override  void  VCElementB(CElementB  ceb)  {          //  accion     abstract  class  Visitor  {      }      public  abstract  void  VCElementA(CElementA  cea);   }      public  abstract  void  VCElementB(CElementB  ceb);   }   abstract  class  Element  {      public  abstract  void  Accept(Visitor  visitor);   }  
  106. 106. Visitor class  ObjectStructure  {   class  CElementA  :  Element  {      private  List<Element>  _elements  =  new  List<Element>();      public  override  void  Accept(Visitor  visitor)  {      public  void  Attach(Element  element)  {          visitor.VisitConcreteElementA(this);          _elements.Add(element);      }      }      public  void  OperationA()  {      public  void  Detach(Element  element)  {          _elements.Remove(element);      }      }   }      public  void  Accept(Visitor  visitor)  {          foreach  (Element  element  in  _elements)  {   class  CElementB  :  Element  {              element.Accept(visitor);      public  override  void  Accept(Visitor  visitor)  {          }      }          visitor.VisitConcreteElementB(this);   }      }      public  void  OperationB()  {      }   }  
  107. 107. Visitor statistics group Intelligent Tutoring Systems Conference 2010 109
  108. 108. Memento   GoF.   Behavior of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   With out violating encapsulation, captures and externalize an object state. Intelligent Tutoring Systems Conference 2010 110
  109. 109. Memento class  ObjectStructure  {   class  MainApp  {      private  List<Element>  _elements  =  new  List<Element>();   static  void  Main()  {      public  void  Attach(Element  element)  {   Originator  o  =  new  Originator();          _elements.Add(element);   o.State  =  "On";      }   Caretaker  c  =  new  Caretaker();      public  void  Detach(Element  element)  {          _elements.Remove(element);   c.Memento  =  o.CreateMemento();      }   o.State  =  "Off";      public  void  Accept(Visitor  visitor)  {   o.SetMemento(c.Memento);          foreach  (Element  element  in  _elements)  {   }              element.Accept(visitor);   }          }      }   }   class  Originator  {      private  string  _state;      get  {  return  _state;  }      set  {  _state  =  value;}      public  Memento  CreateMemento()  {          return  (new  Memento(_state));      }      public  void  SetMemento(Memento  memento)  {          State  =  memento.State;      }   }  
  110. 110. Questions Intelligent Tutoring Systems Conference 2010 112
  111. 111. From the storyboard to the code visitor Pro toty unive clon rsity eab p perso e n le Abstr grou ac factor t p y factor y handler proffe so r list stude nt HR re g i s trar regist rar Meth list prin o ter Fact d ory u ct Prod Stra tegy crea dor Intelligent Tutoring Systems Conference 2010 113
  112. 112. 3.4. Design patterns object structure:: the goal “low coupling”
  113. 113. Adapter   GoF.   Structure of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Transform the interface of a class into another interface. Allowing that two classes work together.   Translate the requests of its interface into requests for the other interface. It also do the data translation. Intelligent Tutoring Systems Conference 2010 115
  114. 114. Adapter class  MainApp  {   class  Adaptee  {      static  void  Main()  {      public  void  SpecificRequest()  {          Target  target  =  new  Adapter();          Console.WriteLine("Called  SpecificRequest()");      }          target.Request();   }      }   }   class  Target  {      public  virtual  void  Request()  {          Console.WriteLine("Called  Target  Request()");      }   }   class  Adapter  :  Target  {      private  Adaptee  _adaptee  =  new  Adaptee();      public  override  void  Request()  {          _adaptee.SpecificRequest();      }   }  
  115. 115. Adapter account registar account adapter account Patrones de Codificación Intelligent Tutoring Systems Conference 2010 117
  116. 116. Bridge   GoF.   Structure of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Separates the abstraction of its implementation in such a way that they can change in an independent way. Patrones de Codificación Intelligent Tutoring Systems Conference 2010 118
  117. 117. Bridge class MainApp { abstract class Implementor { static void Main() { public abstract void Operation(); Abstraction ab = new RefinedAbstraction(); } ab.Implementor = new class RefinedAbstraction : Abstraction { ConcreteImplementorA(); public override void Operation() { ab.Operation(); implementor.Operation(); ab.Implementor = new ConcreteImplementorB } (); } ab.Operation(); } class ConcreteImplementorA : Implementor { } public override void Operation() { WriteLine("ConcreteImplementorA Operation"); } class Abstraction { } protected Implementor implementor; public Implementor Implementor { class ConcreteImplementorB : Implementor { set { implementor = value; } public override void Operation() { WriteLine("ConcreteImplementorB Operation"); } } public virtual void Operation() { } implementor.Operation(); } }
  118. 118. Bridge university group implementation group refined group concreate group group registrar Intelligent Tutoring Systems Conference 2010 120
  119. 119. Composite   GoF.   Structure of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Build an object conforming a tree- structure (hierarquicaly structure)   It allows to treat simple-objects and complex-objects in the same way. Patrones de Codificación Intelligent Tutoring Systems Conference 2010 121
  120. 120. Composite    class  Composite  :  Component  {          private  List<Component>  _children     class  MainApp  {          =  new  List<Component>();      static  void  Main()  {          public  Composite(string  name)  :  base(name)  {          Composite  root  =  new  Composite("root");          }          root.Add(new  Leaf("Leaf  A"));          public  override  void  Add(Component  component)  {          root.Add(new  Leaf("Leaf  B"));              _children.Add(component);          }          Composite  comp  =  new  Composite("Composite  X");          public  override  void  Remove(Component  component)  {          comp.Add(new  Leaf("Leaf  XA"));              _children.Remove(component);          comp.Add(new  Leaf("Leaf  XB"));          }          root.Add(comp);          public  override  void  Display(int  depth)  {          root.Add(new  Leaf("Leaf  C"));              Console.WriteLine(new  String('-­‐',  depth)  +  name);              foreach  (Component  component  in  _children)  {          root.Display(1);                  component.Display(depth  +  2);      }              }   }          }   abstract  class  Component  {    }      protected  string  name;   class  Leaf  :  Component  {      public  Component(string  name)  {      public  Leaf(string  name)  :  base(name)  {      }          this.name  =  name;      public  override  void  Add(Component  c)  {      }      }      public  abstract  void  Add(Component  c);      public  override  void  Remove(Component  c)  {      public  abstract  void  Remove(Component  c);      }      public  abstract  void  Display(int  depth);      public  override  void  Display(int  depth)  {   }      }   }  
  121. 121. Composite homework image text Intelligent Tutoring Systems Conference 2010 123
  122. 122. Decorator   GoF.   Structure of objects.   Low coupled: modifying a point in the code do not alter the system’s structure.   Dynamicaly add additional responsabilities to an object.   The decorator is a flexible alternative of the subclases to extent the functionality. Patrones de Codificación Intelligent Tutoring Systems Conference 2010 124
  123. 123. Decorator abstract  class  Decorator  :  Component  {   class  MainApp  {      protected  Component  component;      static  void  Main()  {      public  void  SetComponent(Component  component)  {          ConcreteComponent  c  =  new                                          this.component  =  component;    ConcreteComponent();      }        public  override  void  Operation()  {          ConcreteDecoratorA  d1  =  new          if  (component  !=  null)  {    ConcreteDecoratorA();              component.Operation();          ConcreteDecoratorB  d2  =  new          }    ConcreteDecoratorB();      }          d1.SetComponent(c);   }          d2.SetComponent(d1);   class  ConcreteDecoratorA  :  Decorator  {          d2.Operation();      public  override  void  Operation()  {          base.Operation();      }          WriteLine("ConcreteDecoratorA.Operation()");   }      }   abstract  class  Component  {   }      public  abstract  void  Operation();   class  ConcreteDecoratorB  :  Decorator  {   }      public  override  void  Operation()  {   class  ConcreteComponent  :  Component  {          base.Operation();          AddedBehavior();      public  override  void  Operation()  {          WriteLine("ConcreteDecoratorB.Operation()");          WriteLine("ConcreteComponent.Operation()");      }      }      void  AddedBehavior()  {   }      }   }  
  124. 124. Decorator component decorator list attendance grade Intelligent Tutoring Systems Conference 2010 126
  125. 125. Facade   GoF.   Structure of objects.   Low coupled: modifying a point in the code do not alter the system’s structure. Patrones de Codificación Intelligent Tutoring Systems Conference 2010 127
  126. 126. Facade class  SubSystemFour  {      public  void  MethodFour()  {   class  MainApp  {          Console.WriteLine("  SubSystemFour  Method");      }      public  static  void  Main()  {   }          Facade  facade  =  new  Facade();   class  Facade  {          facade.MethodA();      private  SubSystemOne  _one;          facade.MethodB();      private  SubSystemTwo  _two;      }      private  SubSystemThree  _three;      private  SubSystemFour  _four;   }      public  Facade()  {   class  SubSystemOne  {          _one  =  new  SubSystemOne();      public  void  MethodOne()  {          _two  =  new  SubSystemTwo();          WriteLine("  SubSystemOne  Method");          _three  =  new  SubSystemThree();      }          _four  =  new  SubSystemFour();   }      }      public  void  MethodA()  {   class  SubSystemTwo  {          Console.WriteLine("nMethodA()  -­‐-­‐-­‐-­‐  ");      public  void  MethodTwo()  {          _one.MethodOne();          WriteLine("  SubSystemTwo  Method");          _two.MethodTwo();      }          _four.MethodFour();   }      }   class  SubSystemThree  {      public  void  MethodB()  {          Console.WriteLine("nMethodB()  -­‐-­‐-­‐-­‐  ");      public  void  MethodThree()  {          _two.MethodTwo();            WriteLine("  SubSystemThree  Method");          _three.MethodThree();      }      }   }   }  
  127. 127. Facade university treasury HR registrar Intelligent Tutoring Systems Conference 2010 129
  128. 128. GoF 130
  129. 129. Questions Intelligent Tutoring Systems Conference 2010 131
  130. 130. Reflection How many members on the team? How much time? How many classes or modules? How many LOC? Standards Testing / Validation Relations Intelligent Tutoring Systems Conference 2010 132

×