Decorators in Software Design

 
W
e
e
k
 
5
,
 
D
a
y
 
2
:
D
e
c
o
r
a
t
o
r
 
Decorators
Muddiest Point
 
Tomorrow:
Quiz on lab reading:
https://faculty-
web.msoe.edu/hasker/se2811/labs/5/
 
 
 
 
 
SE-2811
Slide design: Dr. Mark L. Hornick
Content: Dr. Hornick
Errors: Dr. Yoder
 
1
 
C
o
f
f
e
e
 
I
n
h
e
r
i
t
a
n
c
e
 
M
o
d
e
l
D
e
s
i
g
n
 
R
e
v
i
e
w
 
Any potential changes?
Keep current design?
 
SE-2811
Dr. Mark L. Hornick
 
2
 
T
i
m
e
 
f
o
r
 
C
o
f
f
e
e
 
2
.
0
 
Want to be able to add, Whip, Mocha,
DarkRoast, etc. to our coffee
Exercise: With your team, create a design to
include these “decorators” and have the cost
function return their cost
 
SE-2811
Dr. Mark L. Hornick
 
3
 
O
n
e
 
a
p
p
r
o
a
c
h
:
 
I
n
h
e
r
i
t
a
n
c
e
 
 
SE-2811
Dr. Mark L. Hornick
 
4
 
C
l
e
a
n
e
d
 
u
p
 
w
i
t
h
 
d
e
c
o
r
a
t
o
r
p
a
t
t
e
r
n
 
 
SE-2811
Dr. Mark L. Hornick
 
5
 
C
o
s
t
 
o
f
 
D
a
r
k
R
o
a
s
t
 
w
i
t
h
 
W
h
i
p
a
n
d
 
M
o
c
h
a
 
 
SE-2811
Dr. Mark L. Hornick
 
6
 
Whip
 
Mocha
 
DarkRoast
 
cost()
 
cost()
 
cost()
 
0.99
 
0.20
 
0.10
 
$1.29
 
G
e
n
e
r
a
l
 
P
a
t
t
e
r
n
 
 
SE-2811
Dr. Mark L. Hornick
Wikipedia
 
7
 
E
x
a
m
p
l
e
 
2
:
 
B
y
t
e
 
I
n
p
u
t
 
S
t
r
e
a
m
s
 
 
SE-2811
Dr. Mark L. Hornick
 
8
 
E
x
 
3
:
 
B
i
k
e
s
 
 
SE-2811
Dr. Mark L. Hornick
 
9
 
E
x
 
4
:
 
E
m
p
l
o
y
e
e
s
 
 
SE-2811
Dr. Mark L. Hornick
http://zishanbilal.files.wordpress.com/2011/04/042811_2030_designpatte31.png
 
10
 
D
e
s
i
g
n
 
P
r
i
n
c
i
p
l
e
s
 
Reduce coupling
Increase cohesion
Encapsulate what varies
Favor composition over inheritance
Program to interfaces, not implementations
C
l
a
s
s
e
s
 
s
h
o
u
l
d
 
b
e
 
o
p
e
n
 
f
o
r
 
e
x
t
e
n
s
i
o
n
 
b
u
t
c
l
o
s
e
d
 
f
o
r
 
m
o
d
i
f
i
c
a
t
i
o
n
Which of these are met?
 
SE-2811
Dr. Mark L. Hornick
 
11
 
D
o
w
n
s
i
d
e
s
 
What are the disadvantages of decorators?
 
 
SE-2811
Dr. Mark L. Hornick
 
12
 
SE-2811
Dr. Mark L. Hornick
 
13
 
K
n
o
w
i
n
g
 
t
h
a
t
 
t
h
e
 
i
n
p
u
t
 
s
t
r
e
a
m
 
c
l
a
s
s
e
s
 
a
r
e
b
a
s
e
d
 
o
n
 
t
h
e
 
D
e
c
o
r
a
t
o
r
 
p
a
t
t
e
r
n
 
c
a
n
 
m
a
k
e
t
h
i
n
g
s
 
e
a
s
i
e
r
 
SE-2811
Dr. Mark L. Hornick
 
14
 
<<deprecated>>
 
<<deprecated>>
 
T
h
e
 
D
e
c
o
r
a
t
o
r
 
p
a
t
t
e
r
n
 
a
p
p
l
i
e
d
 
t
o
 
o
u
t
p
u
t
s
t
r
e
a
m
s
 
SE-2811
Dr. Mark L. Hornick
 
15
 
(with other
Variables…)
 
T
h
r
e
a
d
i
n
g
 
M
u
d
d
i
e
s
t
 
P
o
i
n
t
 
[
T
o
b
e
 
r
e
v
i
s
i
t
e
d
 
i
n
 
a
 
f
u
t
u
r
e
 
l
e
c
t
u
r
e
]
 
SE-2811
Dr. Mark L. Hornick
 
16
 
P
a
t
t
e
r
n
s
 
M
u
d
d
i
e
s
t
 
P
o
i
n
t
 
[
T
o
 
b
e
r
e
v
i
s
i
t
e
d
 
i
n
 
a
 
f
u
t
u
r
e
 
l
e
t
u
r
e
]
 
17
Slide Note

SE-2811

Dr. Yoder

Embed
Share

Dive into the world of decorators in software design with Dr. Mark L. Hornick. Explore topics such as decorator patterns, inheritance, design principles, and more. Get ready for a quiz on lab readings and discover how to enhance your coffee model with decorators. Learn about reducing coupling, increasing cohesion, and encapsulating variations in your designs.

  • Decorators
  • Software Design
  • Dr. Mark L. Hornick
  • Design Principles
  • Inheritance

Uploaded on Sep 26, 2024 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: https://faculty- web.msoe.edu/hasker/se2811/labs/5/ SE-2811 1 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder

  2. Coffee Inheritance Model Design Review Any potential changes? Keep current design? SE-2811 2 Dr. Mark L. Hornick

  3. Time for Coffee 2.0 Want to be able to add, Whip, Mocha, DarkRoast, etc. to our coffee Exercise: With your team, create a design to include these decorators and have the cost function return their cost SE-2811 3 Dr. Mark L. Hornick

  4. One approach: Inheritance SE-2811 4 Dr. Mark L. Hornick

  5. Cleaned up with decorator pattern SE-2811 5 Dr. Mark L. Hornick

  6. Cost of DarkRoast with Whip and Mocha cost() cost() cost() 0.10 0.20 0.99 $1.29 DarkRoast Mocha Whip SE-2811 6 Dr. Mark L. Hornick

  7. General Pattern SE-2811 7 Dr. Mark L. Hornick Wikipedia

  8. Example 2: Byte Input Streams SE-2811 8 Dr. Mark L. Hornick

  9. Ex 3: Bikes SE-2811 9 Dr. Mark L. Hornick

  10. Ex 4: Employees SE-2811 10 Dr. Mark L. Hornick http://zishanbilal.files.wordpress.com/2011/04/042811_2030_designpatte31.png

  11. Design Principles Reduce coupling Increase cohesion Encapsulate what varies Favor composition over inheritance Program to interfaces, not implementations Classes should be open for extension but closed for modification Which of these are met? SE-2811 11 Dr. Mark L. Hornick

  12. Downsides What are the disadvantages of decorators? SE-2811 12 Dr. Mark L. Hornick

  13. SE-2811 13 Dr. Mark L. Hornick

  14. Knowing that the input stream classes are based on the Decorator pattern can make things easier class Input Stream Decorators io::FilterInputStream io::InputStream # in: volatile InputStream - - SKIP_BUFFER_SIZE: int = 2048 {readOnly} skipBuffer: byte ([]) # FilterInputStream(InputStream) + read() : int + read(byte[]) : int + read(byte[], int, int) : int + skip(long) : long + available() : int + close() : void + mark(int) : void + reset() : void + markSupported() : boolean + read() : int + read(byte[]) : int + read(byte[], int, int) : int + skip(long) : long + available() : int + close() : void + mark(int) : void + reset() : void + markSupported() : boolean #in io:: BufferedInputStream io::PipedInputStream io:: LineNumberInputStream io::FileInputStream <<deprecated>> io::StringBufferInputStream <<deprecated>> SE-2811 14 Dr. Mark L. Hornick

  15. The Decorator pattern applied to output streams class Output Stream Decorators io::FilterOutputStream io::OutputStream # out: OutputStream + write(int) : void + write(byte[]) : void + write(byte[], int, int) : void + flush() : void + close() : void + FilterOutputStream(OutputStream) + write(int) : void + write(byte[]) : void + write(byte[], int, int) : void + flush() : void + close() : void #out io:: io:: io::DataOutputStream ObjectOutputStream PipedOutputStream io::FileOutputStream Writer io::PrintWriter Appendable io::PrintStream -psOut (with other Variables ) SE-2811 15 Dr. Mark L. Hornick

  16. Threading Muddiest Point [To be revisited in a future lecture] Lambda examples Lambda examples Lambda vs. Anon inner syntax Java 8 Quiz Lambda examples Lambda examples "Effectively Final" All lambda examples the same code? Lambda examples When would you use a Lambda expression over an anonymous class and vice versa? The Lambda is a Java thing, not an intelliJ thing right? whens the next quiz? Agree More examples of using lambdas (didn't get exposure in software dev 2) Effectively Final? SE-2811 16 Dr. Mark L. Hornick

  17. Patterns Muddiest Point [To be revisited in a future leture] We really didn't cover any sorting algorithms and what each's benefits are Can we do an example??? Related to the quiz for below question Do we need to implement code versions of the strategy and factory method patterns?? If so how extensive and will it be similar to how we implemented in class? Implementing the methods needed for the factory method pattern. Is there a flowchart/checklist to determine which pattern is more appropriate to use? Choosing the correct design pattern What are Coupling and Cohesion and is it better to have high or low coupling or cohesion? On a quiz/test would you ask us to draw the uml of a particular general pattern, or would you just ask us to write the code? Why would we use Factory Pattern? How do you know when to use what pattern to solve a problem? Diagrams High/Low Cohesion/Coupling Class Diagram for Factory Design Pattern Nothing 17

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#