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

CSE564 Lecture 15

CSE564 Lecture 15

Software Design
Assignment 03
(202103)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

September 15, 2020
Tweet

Transcript

  1. jgs CSE 564 Software Design Lecture 15: Assignment 03 Dr.

    Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. jgs Proctoring Respondus LockDown Browser

  3. jgs 564 00001110 Proctoring

  4. jgs 564 00001110 Proctoring You need A camera

  5. jgs 564 00001110 Proctoring

  6. jgs 564 00001110 Agenda § Sample Exam is available. Test

    your system ASAP § Read the Online Proctored Exam Guidelines to know what to do in case of a problem during the exam § Midterm Exam available March 10 only during lecture time from 1:30 pm to 2:45 pm. § No lecture that day. Go directly to your exam § It is a CLOSED BOOK exam. Do not use any material § Scratch paper is allowed. Empty White Paper. Show it on camera when you show your environment!
  7. jgs Assignment 03 Patterns

  8. jgs 564 00001110 Assignment 03

  9. jgs 564 00001110 Assignment 03 - UI Main JFrame *Listener

    PlotPanel JButton Run
  10. jgs 564 00001110 Assignment 03 – Observer Pattern Main Observable

    PlotPanel Run Source Observer
  11. jgs 564 00001110 Assignment 03 – Decorator Pattern Main PlotPanel

    Observer Drawable SimplePlot DecoratedPlot MarkedPlot BarPlot
  12. jgs 564 00001110 Assignment 03 – Decorator Pattern BarPlot MarkedPlot

    SimplePlot MarkedPlot SimplePlot SimplePlot
  13. jgs 564 00001110 Assignment 03 – Singleton Pattern PlotPanel Run

    << Singleton >> Evaluator
  14. jgs 564 00001110 Submit Source Code in Java § only

    *.java files § Use only java.swing. Nothing else for UI § Do not use packages (no package instruction in your classes) Class diagram § Submit a PDF or Image file (a PNG file). § Show your classes and all Java API classes used, including JFrame, JPanel, etc.
  15. jgs 564 00001110 Assignment 03

  16. jgs Factory Wrapper of a constructor One entire object to

    be built in a single method call
  17. jgs 564 00001110 GoF Patterns

  18. jgs 564 00001110 Abstract Factory

  19. jgs 564 00001110 Products public interface Shape { void draw();

    } public class RoundedRectangle implements Shape { public void draw() { System.out.println("Inside RoundedRectangle/draw() method."); } } public class RoundedSquare implements Shape { public void draw() { System.out.println("Inside RoundedSquare/draw() method."); } } public class Rectangle implements Shape { public void draw() { System.out.println("Inside Rectangle/draw() method."); } }
  20. jgs 564 00001110 Factories public abstract class AbstractFactory { Shape

    getShape(String shapeType) ; } public class ShapeFactory extends AbstractFactory { public Shape getShape(String shapeType){ if(shapeType.equalsIgnoreCase("RECTANGLE")){ return new Rectangle(); }else if(shapeType.equalsIgnoreCase("SQUARE")){ return new Square(); } return null; } }
  21. jgs 564 00001110 Factories public class RoundedShapeFactory extends AbstractFactory {

    public Shape getShape(String shapeType){ if(shapeType.equalsIgnoreCase("RECTANGLE")){ return new RoundedRectangle(); }else if(shapeType.equalsIgnoreCase("SQUARE")){ return new RoundedSquare(); } return null; } }
  22. jgs 564 00001110 Client 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(); } }
  23. jgs Adapter Convert the interface of a class into another

    interface clients expect
  24. jgs 564 00001110 GoF Patterns

  25. jgs 564 00001110 Adapter

  26. jgs 564 00001110 Example RectangleAdapter + draw Rectangle + draw

    + draw
  27. jgs 564 00001110 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); } }
  28. jgs 564 00001110 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); } }
  29. jgs 564 00001110 Adaptee class Rectangle { public void draw(int

    x, int y, int width, int height) { System.out.println("Rectangle with coordinate left-down point”); } }
  30. jgs 564 00001110 Review § Prototype § Composite § Flyweight

    § Proxy
  31. jgs CSE 564 Computer Systems Fundamentals Javier Gonzalez-Sanchez javiergs@asu.edu Fall

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