Download presentation
Presentation is loading. Please wait.
Published byAbigayle Gibson Modified over 9 years ago
1
Week 9, Class 3: Model-View-Controller Today Happens-Before Adapter and Façade Pattern (high-level) Tuesday: Project code due, 11pm Wednesday: Quiz Choose a pattern Refactor code to meet a design goal Discuss how code/pattern meets a design goal Adapter and Façade Patterns (high-level) Synchronization Friday: Review for Final & Class Climate evaluations SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1
2
The rigormeter is at 2 today https://www.rose-hulman.edu/~bryan/images/rigor.html SE-2811 Dr.Yoder 2
3
Ex. public void a() { System.out.println(“x”); System.out.println(“y”); } public void b() { System.out.println(“x”); System.out.println(“y”); } SE-2811 Dr.Yoder 3 Prove the following code is(n’t) free of data races:
4
Ex. public void a() { x = 5; System.out.println(“x”); } public void a() { x = 5; System.out.println(“x”); } SE-2811 Dr.Yoder 4 Prove the following code is(n’t) free of data races:
5
Ex. public void a() { synchronized { x = 5; System.out.println(“x”); } SE-2811 Dr.Yoder 5 Prove the following code is(n’t) free of data races:
6
Ex. if(theLogger==null){ synchronized (EventLogger.class){ if(theLogger == null){ theLogger = new EventLogger(path); } SE-2811 Dr.Yoder 6 Write whether this code contains any data races. Explain your answer. Assume loggers is not volatile.
7
Ex. if(theLogger==null){ synchronized (EventLogger.class){ if(theLogger == null){ theLogger = new EventLogger(path); } SE-2811 Dr.Yoder 7 Write whether this code contains any data races. Explain your answer. Assume loggers is volatile.
8
Ex. if(loggers.get(path)==null){ synchronized (loggers){ if(loggers.get(path) == null){ Logger logger = new EventLogger(path); loggers.put(path, logger); } SE-2811 Dr.Yoder 8 Write whether this code contains any data races. Explain your answer. Assume loggers is not thread safe.
9
Ex. if(loggers.get(path)==null){ synchronized (loggers){ if(loggers.get(path) == null){ Logger logger = new EventLogger(path); loggers.put(path, logger); } SE-2811 Dr.Yoder 9 Write whether this code contains any data races. Explain your answer. Assume loggers is thread safe.
10
SE-2811 Slide design: Dr. Mark L. Hornick Most Content: Dr. Hornick Some Content and Most Errors: Dr. Yoder The Façade Pattern SE-2811 Dr. Mark L. Hornick 10
11
Watching a Movie... Use multiple interfaces (remotes) to Turn on Receiver/amplifier Turn on TV/Monitor Turn on DVD player Set the Receiver input to DVD Put the Monitor in HDMI input mode Set the Receiver volume to medium Set Receiver to DTS Surround Start the DVD player. Interacting with the following classes: Receiver/Amplifier TV/Monitor DVD Camera with blue screen
12
To decrease the complexity.. We can create a new class TheaterFacade (e.g. a universal remote) which exposes a few methods such as watchMovie(). The façade treats the various components as a sub system and calls on them to implement the watchMovie method. So to watch a movie, we just call one method, watchMovie and it communicates with the Monitor, DVD, and Receiver for us. The façade still leaves the subsystem accessible to be used directly. If you need the advanced functionality of the subsystem classes, they are available for use.
13
The Problem Complex system Consisting of multiple subsystems Each with its own interface, each with many methods Difficult for clients (blue) to deal with
14
Facade Solution Solution Centralize subsystem interface Simplify/reduce number of centralized methods Façade presents new unified “face” to clients Facade
15
Removing the burden from beginning Java developers with a Façade (WinPlotter) SE-2811 Dr. Mark L. Hornick 15
16
Generic Pattern SE-2811 Dr. Mark L. Hornick 16
17
Facade Applications Interface to existing library Unify or “clean up” complex interface
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.