CSE460 Lecture 21

CSE460 Lecture 21

Software Analysis and Design
Singleton
(202010)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez

July 21, 2020
Tweet

Transcript

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

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

    Announcements § Midterm Exam: Monday October 19 § Midterm Review: Friday October 16 § Assignment 03 is due October 16. It about patterns
  3. jgs Previously …

  4. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 4 jgs

    Practice
  5. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 5 jgs

    Solution: UI + Observer + Decorator
  6. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 6 jgs

    Observer Pattern
  7. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 7 jgs

    Decorator Pattern
  8. jgs Let us Continue the Practice

  9. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 9 jgs

    GoF Patterns
  10. jgs Singleton

  11. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 11 jgs

    Singleton A B
  12. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 12 jgs

    Singleton A B Printer DataBaseConnection UniversityPresident Pacman Logger ControlCenter
  13. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 13 jgs

    Singleton
  14. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 14 jgs

    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 } } }
  15. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 15 jgs

    Singleton class Singleton{ private static Singleton instance; // Constructor is 'protected' protected Singleton() {} public static Singleton getInstance(){ if (instance == null){ instance = new Singleton(); } return instance; } }
  16. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 16 jgs

    Practice
  17. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 17 jgs

    Add More Objects
  18. Javier Gonzalez-Sanchez | CSE460 | Fall 2020 | 18 jgs

    A Singleton
  19. 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.