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

CSE460 Lecture 17

CSE460 Lecture 17

Software Analysis and Design
Singleton
(202103)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

July 17, 2020
Tweet

Transcript

  1. jgs CSE 460 Software Analysis and Design Lecture 17: Singleton

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

  3. jgs 00010000 Practice

  4. jgs 00010000 Observer Pattern

  5. jgs 00010000 Decorator Pattern

  6. jgs 00010000 Solution: UI + Observer + Decorator

  7. jgs Let us Continue the Practice

  8. jgs 00010000 GoF Patterns

  9. jgs Singleton

  10. jgs 00010000 Singleton A B

  11. jgs 00010000 Singleton A B Printer DataBaseConnection UniversityPresident Pacman Logger

    ControlCenter
  12. jgs 00010000 Singleton

  13. jgs 00010000 Singleton class Main { 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 } } }
  14. jgs 00010000 Singleton class Singleton{ private static Singleton instance; //

    Constructor is 'protected' protected Singleton() {} public static Singleton getInstance(){ if (instance == null){ instance = new Singleton(); } return instance; } }
  15. jgs 00010000 Practice

  16. jgs 00010000 A Singleton

  17. jgs 00010000 Add More Objects

  18. 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.