CSE460 Lecture 17

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

CSE460 Lecture 17

Software Analysis and Design
Singleton
(202103)

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

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

    Dr. Javier Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. 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 } } }
  3. 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; } }
  4. jgs CSE 460 Software Analysis and Design Javier Gonzalez-Sanchez [email protected]

    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.

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming