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 10. Patterns II

Slide 2

Slide 2 text

Previously

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Observer 4

Slide 5

Slide 5 text

Singleton 5

Slide 6

Slide 6 text

GoF Patterns 6

Slide 7

Slide 7 text

Decorator Composite

Slide 8

Slide 8 text

Decorator | Composite 8

Slide 9

Slide 9 text

Decorator | Composite 9

Slide 10

Slide 10 text

Problem 10

Slide 11

Slide 11 text

Inheritance Approach 11

Slide 12

Slide 12 text

Inheritance Approach 12

Slide 13

Slide 13 text

Inheritance Approach 13

Slide 14

Slide 14 text

Decorator vs Inheritance • Both a llow you to ch a nge how a n object beh a ves. • The decor a tor p a ttern a llows you to extend (decor a te) the function a lity of a n object a t runtime. • Inherit a nce a dds beh a vior a t compil a tion time. 14

Slide 15

Slide 15 text

Decorator | Composite 15

Slide 16

Slide 16 text

Decorator | Composite 16

Slide 17

Slide 17 text

Decorator 17

Slide 18

Slide 18 text

Composite 18

Slide 19

Slide 19 text

Example 19

Slide 20

Slide 20 text

Component 20 https://github.com/CSC3100/Patterns

Slide 21

Slide 21 text

ConcreteComponent | Ball 21 https://github.com/CSC3100/Patterns

Slide 22

Slide 22 text

Decorator 22 https://github.com/CSC3100/Patterns

Slide 23

Slide 23 text

ConcreteDecoratorOne | Bag 23 https://github.com/CSC3100/Patterns

Slide 24

Slide 24 text

ConcreteDecoratorTwo | Box 24 https://github.com/CSC3100/Patterns

Slide 25

Slide 25 text

Main 25 dr a w dr a w dr a w https://github.com/CSC3100/Patterns

Slide 26

Slide 26 text

Composite | Example 26 dr a w

Slide 27

Slide 27 text

Decorator vs Inheritance • Both a llow you to ch a nge how a n object beh a ves. • The decor a tor p a ttern a llows you to extend (decor a te) the function a lity of a n object a t runtime. • Inherit a nce a dds beh a vior a t compil a tion time. 27

Slide 28

Slide 28 text

Homework 28 Reading https://medium.com/javarevisited/software-design-patterns-decorator-in-a-nutshell-eefd2025ea3c

Slide 29

Slide 29 text

Connecting the Dots

Slide 30

Slide 30 text

Application 30

Slide 31

Slide 31 text

Application | GUI 31 Main JFrame ChartPanel JPanel

Slide 32

Slide 32 text

Application | Data Gathering 32 Main JFrame ChartPanel Thread Genius JPanel

Slide 33

Slide 33 text

Application | Observer 33 Main JFrame ChartPanel Thread <> Board Genius JPanel PropertyChange Listener PropertyChange Support

Slide 34

Slide 34 text

MarkerDecoratorShadow MarkerDecoratorDot MarkerSimple Application | Decorator 34 MarkerDecoratorDot MarkerSimple MarkerSimple

Slide 35

Slide 35 text

Main 35 https://github.com/CSC3100/Patterns

Slide 36

Slide 36 text

Genius | Runnable 36 https://github.com/CSC3100/Patterns

Slide 37

Slide 37 text

Board | Singleton, Observable 37 https://github.com/CSC3100/Patterns

Slide 38

Slide 38 text

ChartPanel | Observer 38 https://github.com/CSC3100/Patterns

Slide 39

Slide 39 text

Marker | Decorator 39 https://github.com/CSC3100/Patterns

Slide 40

Slide 40 text

MarkerDecorator | Decorator 40 https://github.com/CSC3100/Patterns

Slide 41

Slide 41 text

MarkerDecoratorBar | Decorator 41 https://github.com/CSC3100/Patterns

Slide 42

Slide 42 text

MarkerDecoratorDot | Decorator 42 https://github.com/CSC3100/Patterns

Slide 43

Slide 43 text

MarkerSimple | Decorator 43 https://github.com/CSC3100/Patterns

Slide 44

Slide 44 text

Note 44 UML Class Diagram

Slide 45

Slide 45 text

Questions 45

Slide 46

Slide 46 text

Questions 46

Slide 47

Slide 47 text

Lab.

Slide 48

Slide 48 text

NumberGenerator.java 48

Slide 49

Slide 49 text

To Do 49 Make it Singleton

Slide 50

Slide 50 text

Screen.java 50

Slide 51

Slide 51 text

Main.java 51

Slide 52

Slide 52 text

To Do 52 Compile and Run

Slide 53

Slide 53 text

To Do 53 Create a Class Diagram

Slide 54

Slide 54 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.