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

CSE564 Lecture 12

CSE564 Lecture 12

Software Design
Singleton
(202109)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

September 12, 2020
Tweet

More Decks by Javier Gonzalez

Other Decks in Programming

Transcript

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

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

  3. jgs 564 00001010 GUI § Click to create cities (as

    many as possible) § Ask for a name for the city (a String) Tempe
  4. jgs 564 00001010 GUI § As soon as there are

    at least 2 cities calculate TSP Tempe PHX
  5. jgs 564 00001010 Test Yourselves: Problem Traveling salesman problem (TSP)

    Given a set of n nodes and distances for each pair of nodes, find a roundtrip of minimal total length visiting each node exactly once.
  6. jgs 564 00001010 Test Yourselves: Problem Traveling salesman problem (TSP)

    Given a set of n nodes and distances for each pair of nodes, find a roundtrip of minimal total length visiting each node exactly once.
  7. jgs 564 00001010 GUI § As soon as there are

    at least 2 cities calculate TSP Tempe PHX LAX
  8. jgs 564 00001010 GUI § Allow the user to drag

    and drop cities to change their position Tempe PHX LAX
  9. jgs 564 00001010 GUI § Allow the user to drag

    and drop cities to change their position Tempe PHX LAX
  10. jgs 564 00001010 GUI § Keep the TSP algorithm working

    (Observer ? Threads?) § Think about performance Tempe PHX LAX NYC
  11. jgs 564 00001010 GUI § Add a JMenuBar with a

    Jmenu (New) to delete all
  12. jgs 564 00001010 GUI § Add a JMenuBar with a

    Jmenu (Save) to store all coordinates for the cities
  13. jgs 564 00001010 Test Yourselves: Data Symmetric

  14. jgs 564 00001010 GUI § Add a JMenuBar with a

    Jmenu (Load) to load all coordinates for the cities
  15. jgs Ideas Drag and Drop

  16. jgs 564 00001010 Demo

  17. jgs 564 00001010 Main.java

  18. jgs 564 00001010 Workspace.java (part 1 / 2)

  19. jgs 564 00001010 Workspace.java (part 2 / 2)

  20. jgs 564 00001010 City.java (part 1 / 2)

  21. jgs 564 00001010 City.java (part 2 /2)

  22. jgs 564 00001010 FAQ § Can we use Java FX?

    No. Use Java Swing § Can I do a different approach? No. Complete the described idea. Do not use inheritance from JComponent (or JComponent subclass) at City. City must be a class for Data § Remember Code is as important as your design. The challenge is for a good and clean design
  23. jgs Note Clean Design

  24. jgs 564 00001010 Clean?

  25. jgs Singleton Design Patterns

  26. jgs 564 00001010 GoF Patterns

  27. jgs 564 00001010 Singleton

  28. jgs 564 00001010 Singleton class MainApp { public static void

    Main(String []a){ // Constructor is protected -- cannot use new Singleton s1 = Singleton.getInstance(); Singleton s2 = Singleton.getInstance(); // Test for same instance if (s1 == s2){ // true - Objects are the same instance } } }
  29. jgs 564 00001010 Singleton class Singleton{ private static Singleton _instance;

    // Constructor is 'protected' protected Singleton() {} public static Singleton getInstance(){ if (_instance == null){ _instance = new Singleton(); } return _instance; } }
  30. jgs 564 00001010 Scenario Quiz Tutor System Companion ControlCenter <<

    singleton>>
  31. jgs 564 00001010 Questions

  32. jgs 564 00001010 Question Did you use If-Else to Identify

    Tokens?
  33. 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.