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

CSC308 Lecture 15

CSC308 Lecture 15

Software Engineering I
Design Patterns - Singleton
(202302)

Javier Gonzalez-Sanchez

October 28, 2022
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSC 308
    Software Engineering 1
    Lecture 15:
    Design Patterns - Singleton
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View full-size slide

  2. jgs
    Previously …

    View full-size slide

  3. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 3
    Project – User create dots

    View full-size slide

  4. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 4
    Project – User selects Cluster and clicks Run

    View full-size slide

  5. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 5
    Project – User selects Cluster and clicks Run

    View full-size slide

  6. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 6
    Project – User selects Line and clicks Run

    View full-size slide

  7. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 7
    Project – User selects Line and clicks Run

    View full-size slide

  8. jgs
    Solution
    The Programmer Approach

    View full-size slide

  9. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 9
    Ideas

    View full-size slide

  10. jgs
    Solution
    The Engineer Approach
    All about modifiability, extensibility, and reuse

    View full-size slide

  11. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 11
    Ideas

    View full-size slide

  12. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 12
    Think About It
    Can we do something about that
    class Repository?

    View full-size slide

  13. jgs
    Singleton
    Design Patterns

    View full-size slide

  14. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 14
    GoF Patterns

    View full-size slide

  15. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 15
    Singleton

    View full-size slide

  16. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 16
    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
    }
    }
    }
    Singleton

    View full-size slide

  17. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 17
    class Singleton{
    private static Singleton _instance;
    // Constructor is 'protected'
    protected Singleton() {}
    public static Singleton getInstance(){
    if (_instance == null){
    _instance = new Singleton();
    }
    return _instance;
    }
    }
    Singleton

    View full-size slide

  18. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 18
    Questions

    View full-size slide

  19. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 19
    Office Hours
    Tuesday and Thursday 3 - 5 pm
    But an appointment required
    Sent me an email – [email protected]

    View full-size slide

  20. jgs
    CSC 308
    Software Engineering 1
    Lab 15:
    Design Patterns
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    www.javiergs.com
    Building 14 -227
    Office Hours: By appointment

    View full-size slide

  21. jgs
    Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 22
    Ideas
    Do you Have
    Questions About Your
    Assignment 02?

    View full-size slide

  22. jgs
    CSC 308 Software Engineering I
    Javier Gonzalez-Sanchez, Ph.D.
    [email protected]
    Winter 2023
    Copyright. These slides can only be used as study material for the class CSC308 at Cal Poly.
    They cannot be distributed or used for another purpose.

    View full-size slide