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

CSE360 Tutorial 07

CSE360 Tutorial 07

Introduction to Software Engineering
Singleton
(202206)

Javier Gonzalez-Sanchez
PRO

June 16, 2022
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. CSE360
    Introduction to Software Engineering
    Lecture:
    Singleton
    Javier Gonzalez-Sanchez
    [email protected]
    javiergs.engineering.asu.edu
    Office Hours: By appointment

    View Slide

  2. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 2
    Project 02
    • User can draw dots on the Screen
    • User select Cluster or Line Box
    • User click the “Run” button
    • Computer Calculate either
    o A line that connect all dots using the
    “nearest neighbor” algorithm
    o Divide the dots in TWO groups (clusters). Some dots became
    red, and others became blue –team Blue and team Red
    • Show results on the screen

    View Slide

  3. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 3
    Second Draft

    View Slide

  4. Singleton

    View Slide

  5. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 5
    GoF Patterns
    Creational Patterns
    • Abstract Factory
    • Builder
    • Factory Method
    • Prototype
    • Singleton
    Structural Patterns
    • Adapter
    • Bridge
    • Composite
    • Decorator
    • Façade
    • Flyweight
    • Proxy
    Behavioral Patterns
    • Chain of Responsibility
    • Command
    • Interpreter
    • Iterator
    • Mediator
    • Memento
    • Observer
    • State
    • Strategy
    • Template Method
    • Visitor

    View Slide

  6. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 6
    Singleton

    View Slide

  7. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 7
    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
    }
    }
    }

    View Slide

  8. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 8
    Singleton
    class Singleton{
    private static Singleton _instance;
    // Constructor is 'protected'
    private Singleton() {}
    public static Singleton getInstance(){
    if (_instance == null){
    _instance = new Singleton();
    }
    return _instance;
    }
    }

    View Slide

  9. Connecting the Dots
    SOLID Principles

    View Slide

  10. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 10
    Connecting the Dots

    View Slide

  11. Javier Gonzalez-Sanchez | CSE360 | Summer 2018 | 11
    Homework
    • Draft of Project 02 is due Monday before our
    lecture.
    • The midterm exam will be Tuesday instead of
    Monday.
    • The final version of Project 02 is due Monday
    midnight. I will answer questions during the lecture
    on Monday.
    • A correct solution is not only a solution that
    “compiles and runs”; but a solution that matches
    the design we have agreed on.

    View Slide

  12. CSE360 – Introduction to Software Engineering
    Javier Gonzalez-Sanchez
    [email protected]
    Summer 2022
    Disclaimer. These slides can only be used as study material for the class CSE360 at ASU. They cannot be distributed or used for another purpose.

    View Slide