Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE460 Lecture 19

CSE460 Lecture 19

Software Analysis and Design
Connecting the Dots
(202103)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

July 19, 2020
Tweet

Transcript

  1. jgs CSE 460 Software Analysis and Design Lecture 19: Connecting

    the Dots Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. jgs 460 0010011 Announcement § Assignment 05 (Patterns) is due

    March 29. It opens at the end of the lecture
  3. jgs 460 0010011 Next

  4. jgs 460 0010011 Factory

  5. jgs 460 0010011 Using a Factory public class Client {

    public static void main(String[] args) { AbstractFactory shapeFactory = new ShapeFactory(); //get an object of Shape Rectangle Shape shape1 = shapeFactory.getShape("RECTANGLE"); //call draw method of Shape Rectangle shape1.draw(); //get an object of Shape Square Shape shape2 = shapeFactory.getShape("SQUARE"); //call draw method of Shape Square shape2.draw(); ] //get shape factory AbstractFactory shapeFactory1 = new RoundedShapeFactory(); //get an object of Shape Rectangle Shape shape3 = shapeFactory1.getShape("RECTANGLE"); //call draw method of Shape Rectangle shape3.draw(); //get an object of Shape Square Shape shape4 = shapeFactory1.getShape("SQUARE"); //call draw method of Shape Square shape4.draw(); } }
  6. jgs 460 0010011 Chain of Responsibility

  7. jgs 460 0010011 Using Chain of Responsibility // Setup Chain

    of Responsibility Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int i=0; i<requests.lenght; i++) { h1.HandleRequest(request[i]); }
  8. jgs 460 0010011 Decorator

  9. jgs 460 0010011 Using a Decorator class MainApp { static

    void main() { // Create ConcreteComponent and two Decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); } }
  10. jgs Adapter Convert the interface of a class into another

    interface clients expect
  11. jgs 460 0010011 Adapter

  12. jgs 460 0010011 Example RectangleAdapter + draw Rectangle + draw

    + draw
  13. jgs 460 0010011 Client public class Client { public static

    void main(String[] args) { Shape shape = new RectangleAdapter(new Rectangle(); int x1 = 10, y1 = 20; int x2 = 30, y2 = 60; shape.draw(x1, y1, x2, y2); } }
  14. jgs 460 0010011 Adapter class RectangleAdapter implements Shape { private

    Rectangle adaptee; public RectangleAdapter(Rectangle rectangle) { this.adaptee = rectangle; } public void draw(int x1, int y1, int x2, int y2) { int x = Math.min(x1, x2); int y = Math.min(y1, y2); int width = Math.abs(x2 - x1); int height = Math.abs(y2 - y1); adaptee.draw(x, y, width, height); } }
  15. jgs 460 0010011 Adaptee class Rectangle { public void draw(int

    x, int y, int width, int height) { System.out.println("Rectangle with coordinate left-down point”); } }
  16. jgs Assignment 04 Connecting the Dots

  17. jgs 460 0010011 Team 1 2 3

  18. jgs 460 0010011 Idea Main Factory Gift Ball Box Envelop

  19. jgs 460 0010011 Idea wrapper2 Main wrapper1 Factory decoration Envelope

    Box Gift wrapper3 ball Supervisor Is big > 10, box Is small < 5, envelop
  20. jgs 460 0010011

  21. jgs 460 0010011 Main

  22. jgs 460 0010011 Factory

  23. jgs 460 0010011 Chain of Responsibilities

  24. jgs 460 0010011 Decorator

  25. jgs 460 0010011 Decorator

  26. jgs 460 0010011 Observer

  27. jgs 460 0010011

  28. jgs CSE 460 Software Analysis and Design Javier Gonzalez-Sanchez javiergs@asu.edu

    Fall 2020 Disclaimer. These slides can only be used as study material for the class CSE460 at ASU. They cannot be distributed or used for another purpose.