Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: ...
-
Upload
derick-knight -
Category
Documents
-
view
219 -
download
0
description
Transcript of Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: ...
![Page 1: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/1.jpg)
Week 5, Day 2:Decorator Decorators Muddiest Point
Tomorrow:Quiz on lab reading:https://faculty-web.msoe.edu/hasker/se2811/labs/5/
SE-2811Slide design: Dr. Mark L. Hornick
Content: Dr. HornickErrors: Dr. Yoder
1
![Page 2: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/2.jpg)
Coffee Inheritance ModelDesign Review Any potential changes? Keep current design?
SE-2811Dr. Mark L. Hornick
2
![Page 3: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/3.jpg)
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-2811Dr. Mark L. Hornick
3
![Page 4: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/4.jpg)
One approach: Inheritance
SE-2811Dr. Mark L. Hornick
4
![Page 5: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/5.jpg)
Cleaned up with decorator pattern
SE-2811Dr. Mark L. Hornick
5
![Page 6: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/6.jpg)
Cost of DarkRoast with Whip and Mocha
SE-2811Dr. Mark L. Hornick
6
WhipMocha
DarkRoast
cost()cost()cost()0.990.200.10$1.29
![Page 7: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/7.jpg)
General Pattern
SE-2811Dr. Mark L. Hornick
Wikipedia
7
![Page 8: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/8.jpg)
Example 2: Byte Input Streams
SE-2811Dr. Mark L. Hornick
8
![Page 9: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/9.jpg)
Ex 3: Bikes
SE-2811Dr. Mark L. Hornick
9
![Page 10: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/10.jpg)
Ex 4: Employees
SE-2811Dr. Mark L. Hornick
http://zishanbilal.files.wordpress.com/2011/04/042811_2030_designpatte31.png
10
![Page 11: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/11.jpg)
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 modificationWhich of these are met?
SE-2811Dr. Mark L. Hornick
11
![Page 12: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/12.jpg)
Downsides What are the disadvantages of decorators?
SE-2811Dr. Mark L. Hornick
12
![Page 13: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/13.jpg)
SE-2811Dr. Mark L. Hornick
13
![Page 14: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/14.jpg)
Knowing that the input stream classes are based on the Decorator pattern can make things easier
SE-2811Dr. Mark L. Hornick
14
class Input Stream Decorators
io::InputStream
- SKIP_BUFFER_SIZE: int = 2048 {readOnly}- skipBuffer: byte ([])
+ read() : int+ read(byte[]) : int+ read(byte[], int, int) : int+ skip(long) : long+ available() : int+ close() : void+ mark(int) : void+ reset() : void+ markSupported() : boolean
io::FilterInputStream
# in: volatile InputStream
# 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
io::FileInputStream
io::StringBufferInputStream
io::PipedInputStream io::LineNumberInputStream
io::BufferedInputStream
#in
<<deprecated>>
<<deprecated>>
![Page 15: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/15.jpg)
The Decorator pattern applied to output streams
SE-2811Dr. Mark L. Hornick
15
class Output Stream Decorators
io::OutputStream
+ write(int) : void+ write(byte[]) : void+ write(byte[], int, int) : void+ flush() : void+ close() : void
io::FilterOutputStream
# out: OutputStream
+ FilterOutputStream(OutputStream)+ write(int) : void+ write(byte[]) : void+ write(byte[], int, int) : void+ flush() : void+ close() : void
io::FileOutputStream
Appendableio::PrintStream
io::PipedOutputStream
Writerio::PrintWriter
io::ObjectOutputStream io::DataOutputStream
#out
-psOut
(with otherVariables…)
![Page 16: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/16.jpg)
Threading Muddiest Point [To be revisited in a future lecture]
All lambda examples the same code? Lambda examples
Lambda examplesLambda examples
When would you use a Lambda expression over an anonymous class and vice versa?
Lambda vs. Anon inner syntax
The Lambda is a Java thing, not an intelliJ thing right? Java 8whens the next quiz? Quiz
AgreeLambda examples
More examples of using lambdas (didn't get exposure in software dev 2)Lambda examples
Effectively Final?"Effectively Final"
SE-2811Dr. Mark L. Hornick
16
![Page 17: Week 5, Day 2: Decorator Decorators Muddiest Point Tomorrow: Quiz on lab reading: web.msoe.edu/hasker/se2811/labs/5/ SE-2811 Slide design:](https://reader035.fdocuments.us/reader035/viewer/2022062600/5a4d1b927f8b9ab0599c18f1/html5/thumbnails/17.jpg)
Patterns Muddiest Point [To be revisited in a future leture]We really didn't cover any sorting algorithms and what each's benefits areCan we do an example???Related to the quiz for below questionDo 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 patternWhat 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?DiagramsHigh/Low Cohesion/CouplingClass Diagram for Factory Design PatternNothing
17