Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

jgs Previously …

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

jgs Solution The Programmer Approach

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

jgs Singleton Design Patterns

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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]

Slide 20

Slide 20 text

jgs

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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.