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

Slide 2

Slide 2 text

GoF Patterns 2

Slide 3

Slide 3 text

Singleton 3

Slide 4

Slide 4 text

Observer 4

Slide 5

Slide 5 text

Decorator Composite

Slide 6

Slide 6 text

Decorator | Composite 6

Slide 7

Slide 7 text

Decorator | Composite 7

Slide 8

Slide 8 text

Problem 8

Slide 9

Slide 9 text

Inheritance Approach 9

Slide 10

Slide 10 text

Inheritance Approach 10

Slide 11

Slide 11 text

Inheritance Approach 11

Slide 12

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

Slide 13

Slide 13 text

Decorator | Composite 13

Slide 14

Slide 14 text

Decorator | Composite 14

Slide 15

Slide 15 text

Decorator 15

Slide 16

Slide 16 text

Composite 16

Slide 17

Slide 17 text

Example 17

Slide 18

Slide 18 text

Component abstract class Component { public abstract void operation(); } 18 https://github.com/CSC3100/Patterns

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Decorator abstract class Decorator extends Component { protected Component component; public void setComponent(Component component) { this.component = component; } @override public void operation() { if (component != null) { component.operation(); } } } 20 https://github.com/CSC3100/Patterns

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Composite | Example 24 dr a w

Slide 25

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Connecting the Dots

Slide 28

Slide 28 text

Application 28

Slide 29

Slide 29 text

Application | GUI 29 Main JFrame ChartPanel JPanel

Slide 30

Slide 30 text

Application | Data Gathering 30 Main JFrame ChartPanel Thread Genius JPanel

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

MarkerDecoratorShadow MarkerDecoratorDot MarkerSimple Application | Decorator 32 MarkerDecoratorDot MarkerSimple MarkerSimple

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

Note 42 UML Class Diagram

Slide 43

Slide 43 text

Questions 43

Slide 44

Slide 44 text

Lab.

Slide 45

Slide 45 text

To Do 45 Compile and Run

Slide 46

Slide 46 text

To Do 46 Create a Class Diagram

Slide 47

Slide 47 text

CSC 307 Introduction to Software Engineering Javier Gonzalez-Sanchez, Ph.D. [email protected] Winter 2026 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.