Slide design: Dr. Mark L. Hornick SE-2811 5/6/2019 Week 6, Day 1: Decorator Return Half-Exam 1 & Quiz 4 (I have them with me) Decorators Muddiest Point SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder Dr. Yoder
HW SE-2811 5/6/2019 By Monday at 10am, email to me a Writer decorator that implements a Caesar cipher. The user should supply an integer key when creating the wrapper The CaesarWriter should add the key to the value of each character that is written to the stream. If the value goes above 255, it should wrap around through 0. Be sure to include the template write(String str, int off, int len) from ScrambleWriter We will run and debug your code in class. Dr. Yoder
(Review) (Byte) Output Streams SE-2811 5/6/2019 (Review) (Byte) Output Streams Byte output stream (with other Variables…) SE-2811 Dr. Mark L. Hornick Dr. Yoder
(Review) (Char) Writers SE-2811 5/6/2019 (Review) (Char) Writers OutputStreams write (8-bit) bytes. Writers write 16-bit Unicode code-points You can wrap a PrintWriter around a PrintStream You cannot wrap a PrintStream around a PrintWriter (unless you write the code yourself.) TODO: Copy some of the really cool code-points students found last year SE-2811 Dr. Mark L. Hornick Dr. Yoder
In-class exercise: Modify the code to de-scramble the stream 5/6/2019 In-class exercise: Modify the code to de-scramble the stream Writer writer = new ScrambleWriter(new StarInserter(new PrintWriter( System.out)))); //------- Your code here: --------- //------- End your code ---------- PrintWriter printWriter = new PrintWriter(writer,true); SE-2811 Dr. Mark L. Hornick Dr. Yoder
Design Principles T/? Reduce coupling T Increase cohesion 5/6/2019 Design Principles T/? Reduce coupling T Increase cohesion T Encapsulate what varies T Favor composition over inheritance T Program to interfaces, not implementations T Classes should be open for extension but closed for modification Which of these are met? (Avoid coupling) Strive for loosely coupled designs between objects that interact SE-2811 Dr. Mark L. Hornick Dr. Josiah Yoder
Downsides What are the disadvantages of decorators? SE2811 5/6/2019 Large number of small classes overwhelming to new developers Problem when people rely on specific types without thinking through [TODO: Study & find example] Complexity of wrapping SE-2811 Dr. Mark L. Hornick Dr. Josiah Yoder
https://www.polleverywhere.com/free_text_polls/zIp2tH2IVWjXv4H SE-2811 5/6/2019 Muddiest Point SE-2811 Dr. Mark L. Hornick Dr. Yoder
Threading Muddiest Point [To be revisited in a future lecture] SE-2811 5/6/2019 Threading Muddiest Point [To be revisited in a future lecture] All lambda examples the same code? Lambda 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 8 whens the next quiz? Quiz Agree More examples of using lambdas (didn't get exposure in software dev 2) Effectively Final? "Effectively Final" SE-2811 Dr. Mark L. Hornick Dr. Yoder
Patterns Muddiest Point [To be revisited in a future lecture] SE-2811 5/6/2019 Patterns Muddiest Point [To be revisited in a future lecture] 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 Dr. Yoder