Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227 CSC 307 Introduction to Software Engineering Lecture 09. Patterns

Slide 2

Slide 2 text

Homework Quiz 2

Slide 3

Slide 3 text

Previously

Slide 4

Slide 4 text

Relationships 4 Association Directed Association Reflexive Association Multiplicity Aggregation Composition Generalization Realization

Slide 5

Slide 5 text

Good Code vs Bad Code 5

Slide 6

Slide 6 text

Not Everything that Can be … Should be … 6

Slide 7

Slide 7 text

Not Everything that Can be … Should be … 7

Slide 8

Slide 8 text

Patterns

Slide 9

Slide 9 text

De f inition • Design patterns a re solutions to softw a re design problems you f ind a g a in a nd a g a in in re a l-world a pplic a tion development. • P a tterns a re a bout reusable designs a nd inter a ctions between objects. • The 23 G a ng of Four (GoF) patterns a re gener a lly considered the found a tion for a ll other p a tterns (G a mm a , Helm, Johnson, a nd Vlissides). 9

Slide 10

Slide 10 text

GoF Patterns 10

Slide 11

Slide 11 text

Singleton

Slide 12

Slide 12 text

Singleton 12

Slide 13

Slide 13 text

Singleton 13 https://github.com/CSC3100/Patterns

Slide 14

Slide 14 text

Singleton 14 https://github.com/CSC3100/Patterns

Slide 15

Slide 15 text

Warning 15 Do not Abuse of the Singleton You are transforming OOP into Structural Programming!! 🙈

Slide 16

Slide 16 text

Homework 16 Reading https://medium.com/javarevisited/design-patterns-101-hello-singleton-2d3f227c7729

Slide 17

Slide 17 text

Observer

Slide 18

Slide 18 text

Observer 18

Slide 19

Slide 19 text

Classroom | Initial Version 19 https://github.com/CSC3100/Patterns

Slide 20

Slide 20 text

Student | Initial Version 20 https://github.com/CSC3100/Patterns

Slide 21

Slide 21 text

Teacher | Initial Version 21 https://github.com/CSC3100/Patterns

Slide 22

Slide 22 text

Observer 22

Slide 23

Slide 23 text

Observer 23 https://github.com/CSC3100/Patterns

Slide 24

Slide 24 text

Observable 24 https://github.com/CSC3100/Patterns

Slide 25

Slide 25 text

Classroom | New Version 25 https://github.com/CSC3100/Patterns

Slide 26

Slide 26 text

Student | New Version 26 https://github.com/CSC3100/Patterns

Slide 27

Slide 27 text

Teacher | New Version 27 https://github.com/CSC3100/Patterns

Slide 28

Slide 28 text

Important 28 Do not reinvent the wheel! (Do not make another implementation for classes Observer or Observable -they already exist in libraries!)

Slide 29

Slide 29 text

Important 29 Depreciated java.util.Observer java.util.Observable The implementation of these packages That is NOT about the Observer pattern being depreciated.

Slide 30

Slide 30 text

Important 30 Use java.beans.PropertyChangeListener java.beans.PropertyChangeSupport

Slide 31

Slide 31 text

Classroom | Listener Version 31 https://github.com/CSC3100/Patterns

Slide 32

Slide 32 text

Student | Listener Version 32 https://github.com/CSC3100/Patterns

Slide 33

Slide 33 text

Teacher | Listener Version 33 https://github.com/CSC3100/Patterns

Slide 34

Slide 34 text

Thoughts? 34

Slide 35

Slide 35 text

Homework 35 Reading https://medium.com/swlh/software-design-patterns-why-what-and-an-example-8d4c0934a6ca

Slide 36

Slide 36 text

Test Yourselves

Slide 37

Slide 37 text

Problem • Im a gine a cl a ss Te a cher running in its own execution thre a d, forever gr a ding—recording gr a des a s a collection of numeric a l v a lues. • A p a nel (PrinterP a nel) would like to show the gr a des a s they a re gener a ted. • Another p a nel (St a tistic a lP a nel) would like to show re a l-time st a tistics a bout the gr a des (how m a ny p a ss a nd how m a ny f a il). 37

Slide 38

Slide 38 text

Questions 38

Slide 39

Slide 39 text

Lab.

Slide 40

Slide 40 text

Lab 40 Draft a Class Diagram

Slide 41

Slide 41 text

Code public class B implements E { public B() { C c1 = new C(); } public void method(X x) { x.m() B b = new B(); b.sleep(); } } public class Y { X x = new X(); B b = new B(); } public class A extends B { C c1, c2; public A() { c1 = new C(); } public void method() { D d = new D(); d.working(); } } public class X { B var = new A(); public void m() { double x – Math.sqrt(5); } }

Slide 42

Slide 42 text

Let’s work 42

Slide 43

Slide 43 text

CSC 307 Introduction to Software Engineering Javier Gonzalez-Sanchez, Ph.D. [email protected] Spring 2025 Copyright. These slides can only be used as study material for the class CSC307 at Cal Poly. They cannot be distributed or used for another purpose.