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

CSE564 Lecture 15

CSE564 Lecture 15

Software Design
Review II
(202110)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

September 15, 2020
Tweet

More Decks by Javier Gonzalez

Other Decks in Programming

Transcript

  1. jgs CSE 564 Software Design Lecture 15: Midterm Review Dr.

    Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. jgs Previously …

  3. jgs 564 00010000 Scenario CompanionHelper CompanionTroll Companion CompanionTrollHelper

  4. jgs 564 00010000 Decorator

  5. jgs 564 00010000 Main

  6. jgs 564 00010000 Companion public interface Companion { public void

    doSomething(); }
  7. jgs 564 00010000 BasicCompanion public class BasicCompanion implements Companion {

    @Override public void doSomething() { System.out.print("Hello Student, "); } }
  8. jgs 564 00010000 CompanionDecorator public class CompanionDecorator implements Companion {

    protected Companion c; public void add(Companion c){ this.c = c; } @Override public void doSomething() { this.c.doSomething(); } }
  9. jgs 564 00010000 HelperCompanion public class HelperCompanion extends CompanionDecorator {

    @Override public void doSomething(){ super.doSomething(); System.out.print(" I am here to help you. "); } }
  10. jgs 564 00010000 AffectiveCompanion public class AffectiveCompanion extends CompanionDecorator {

    @Override public void doSomething(){ super.doSomething(); System.out.print(" I am here to cheer you."); } }
  11. jgs Test Yourselves GUI Application

  12. jgs 564 00010000 Decorator

  13. jgs 564 00010000 GUI

  14. jgs 564 00010000 Main import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

    import javax.swing.*; public class Main extends JFrame implements ActionListener { CompanionPanel companionPanel = new CompanionPanel (); JButton b1 = new JButton("standard"); JButton b2 = new JButton("help"); JButton b3 = new JButton("affect"); JButton b4 = new JButton("helper+affect"); public Main() { setLayout(new BorderLayout(3,2)); add (companionPanel, BorderLayout.CENTER); JPanel control = new JPanel(new GridLayout(1,4)); control.add (b1); b1.addActionListener(this); control.add (b2); b2.addActionListener(this); control.add (b3); b3.addActionListener(this); control.add (b4); b4.addActionListener(this); add (control, BorderLayout.SOUTH); }
  15. jgs @Override public void actionPerformed(ActionEvent e) { if (e.getSource()==b1) {

    BasicCompanion basic = new BasicCompanion(); panel.setCompanion(basic); panel.showYourself(); } else if (e.getSource()==b2) { BasicCompanion basic = new BasicCompanion(); HelperCompanion helper = new HelperCompanion(); helper.add(basic); panel.setCompanion(helper); panel.showYourself(); } else if (e.getSource()==b3) { BasicCompanion basic = new BasicCompanion(); AffectiveCompanion h = new AffectiveCompanion(); h.add(basic); panel.setCompanion(h); panel.showYourself(); } else if (e.getSource()==b4) { HelperCompanion helper2 = new HelperCompanion(); AffectiveCompanion affective = new AffectiveCompanion(); BasicCompanion basic2 = new BasicCompanion(); helper2.add(affective); affective.add(basic2); panel.setCompanion(helper2);panel.showYourself(); } } public static void main(String[] args) { JFrame main = new Main(); main.setSize(500,500); main.setVisible(true); main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  16. jgs 564 00010000 CompanionPanel import java.awt.GridLayout; import javax.swing.JLayeredPane; public class

    CompanionPanel extends JLayeredPane{ public Companion brain; public void setCompanion(Companion x) { brain = x; } public void showYourself() { removeAll(); setLayout(new GridLayout(1,1)); brain.doSomething(this); revalidate(); } }
  17. jgs 564 00010000 Companion import javax.swing.JComponent; public interface Companion {

    public void doSomething(JComponent panel); }
  18. jgs 564 00010000 BasicCompanion import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JLabel;

    public class BasicCompanion implements Companion { @Override public void doSomething(JComponent panel) { ImageIcon face = new ImageIcon("src/face.png"); JLabel label = new JLabel(); label.setIcon(face); label.setHorizontalTextPosition(JLabel.CENTER); label.setVerticalTextPosition(JLabel.BOTTOM); label.setText("Hello Student, "); panel.add(label); } }
  19. jgs 564 00010000 CompanionDecorator import javax.swing.JComponent; public class CompanionDecorator implements

    Companion { protected Companion c; public void add(Companion c){ this.c=c; } @Override public void doSomething(JComponent panel) { this.c.doSomething(panel); } }
  20. jgs 564 00010000 AffectiveCompanion import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JLabel;

    public class AffectiveCompanion extends CompanionDecorator { @Override public void doSomething(JComponent panel){ super.doSomething(panel); ImageIcon face = new ImageIcon("src/cheer.png"); JLabel label = new JLabel(); label.setIcon(face); label.setHorizontalTextPosition(JLabel.CENTER); label.setVerticalTextPosition(JLabel.BOTTOM); label.setText("I am here to cheer you."); panel.add(label); } }
  21. jgs 564 00010000 HelperCompanion import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JLabel;

    public class HelperCompanion extends CompanionDecorator { @Override public void doSomething(JComponent panel){ super.doSomething(panel); ImageIcon face = new ImageIcon("src/bubble.png"); JLabel label = new JLabel(); label.setIcon(face); label.setHorizontalTextPosition(JLabel.CENTER); label.setVerticalTextPosition(JLabel.BOTTOM); label.setText("I am here to help you."); panel.add(label); } }
  22. jgs Midterm Review GUI Application

  23. jgs The following slides shows some examples related to some

    topics This is NOT a comprehensive list of topics Topics in the exam can be found Weeks 1 to 9 (Lectures 1 to 16)
  24. jgs 564 00010000 Topics 1. Program Development by Stepwise Refinement,

    N. Wirth. 1971 2. On the Criteria To Be Used in Decomposing Systems into Modules, D.L. Parnas. 1972 3. A Laboratory For Teaching Object-Oriented Thinking, K. Beck. 1989 4. Programming in the Large vs Programming in the Small, F. DeRemer et al. 1975 5. Design Patterns: Abstraction and Reuse of Object-Oriented Design, E. Gamma et al. 1993
  25. jgs 564 00010000 1. Stepwise Refinement • Niklaus Wirth. §

    Modularity § Function § Function-driven development § Decomposition § What criteria to use in dividing the system into modules? § Task § Steps § Quality attributes § Software Design is …
  26. jgs 564 00010000 2. Decomposing Systems into Modules § Module

    § What criteria to use in dividing the system into modules? § Information Hiding § Data Structure § What is the difference of Function vs Module? § What is the difference of Task vs Responsibility? § Software Design is …
  27. jgs 564 00010000 3. Programming in the large § High-cohesion

    and loose-coupling § Software Design is … § Programming versus Structuring § Development: Many small programs(modules) written by different people. § Architecture: Structuring a large collection of modules to form a "system" § Composition § Decomposition § Accessibility (public, private) § Hierarchy
  28. jgs 564 00010000 4. Teaching Object-Oriented Thinking § Designs as

    an abstract level as having processes, data flows, and data stores, regardless of implementation language or operating environment. § Procedure, Function Method, Module, Unit, System § Class, Object § Task, Responsibility, Collaborator § Encapsulation / Accessibility § Hierarchical Relationships § Composition / Decomposition § Levels § Linking
  29. jgs 564 00010000 4. Teaching Object-Oriented Thinking Association Directed Association

    Reflexive Association Multiplicity Aggregation Composition Generalization Realization
  30. jgs 564 00010000 5. Design Patterns § Solutions to software

    design problems you find again and again in real-world application development. § Reusable designs and interactions between objects. § Behavior, Creation, Structure
  31. jgs 564 00010000 5. Design Patterns

  32. jgs 564 00010000 From the Assignments § Programming with Java

    § Clean Code (basics) § GUI in Java (Swing / AWT) § Patterns in Java Libraries / Frameworks
  33. jgs Test Yourselves Connecting all

  34. jgs 564 00010000 Assignment 03

  35. jgs 564 00010000 Assignment 03 - UI Main JFrame *Listener

    PlotPanel JButton Run
  36. jgs 564 00010000 Assignment 03 – Observer Pattern Main Observable

    PlotPanel Run Source Observer
  37. jgs 564 00010000 Assignment 03 – Decorator Pattern Main PlotPanel

    Observer Drawable SimplePlot DecoratedPlot MarkedPlot BarPlot
  38. jgs 564 00010000 Assignment 03 – Decorator Pattern BarPlot MarkedPlot

    SimplePlot MarkedPlot SimplePlot SimplePlot
  39. jgs 564 00010000 Assignment 03 – Singleton Pattern PlotPanel Run

    << Singleton >> Evaluator
  40. jgs 564 00010000 Assignment 03

  41. jgs 564 00010000 Questions

  42. jgs CSE 564 Software Design Javier Gonzalez-Sanchez, Ph.D. javiergs@asu.edu Fall

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