Theater Management Project
A home theater set:
DVD player, a projector, automatic screen, surround sound, popcorn machine, required to complete home theater functions, which process is: directly with the remote control: the switching device co-ordinate
opening popcorn machine down screen on stereo projector open
open DVD, selected from dvd
get popcorn dim the lights play
View Movies after closing the various devices
Traditional approaches to solving Theater Management
Traditional approaches to solving Theater Management Analysis
- In the main method ClientTest, create objects of various subsystems, and direct calls to the subsystems (objects) correlation method, the calling process will result in confusion, there is no clear process
- Is not conducive to the ClientTest, the operation of the subsystem to maintain
- Solution: Define a high-level interface to a set of subsystem interface provides a consistent interface (such as providing four methods ready, play, pause, end in a high-level interface), the interface used to access a group of subsystems
- That is, by defining a consistent interface (interface type) for shielding the internal details of the subsystem, so that the calling terminal simply call with the interface occurs, without caring about the details of the internal subsystem => Appearance Model
Basic introduction to skin mode
basic introduction
- Facade pattern (Facade), also known as the "process approach: Facade pattern provides a consistent interface subsystem of a set of interfaces, this model defines a high-level interface that makes the subsystem easier to use
- Appearance pattern by defining a consistent interface to shield the internal details of the subsystem, such that only calling terminal calls the interface with this occurs, without caring about the details of the internal subsystem
Patterns for the appearance of FIG class
class diagram illustrating (classification character appearance model)
- Appearance category (Facade): to provide a unified call interface for the call ends, the appearance of the class to know which subsystem is responsible for processing requests, which will end the call to the appropriate subsystem object request broker
- The caller (Client): the caller appearance of the interface
- Collection subsystem: means modules or subsystems, the processing tasks assigned Facade subject who does the actual function of the provider
Facade pattern to solve Theater Management
Traditional approaches to solving Theater Management Description
- Appearance conversion mode can be understood as a group of interfaces, customers simply call a port, without invoking multiple interfaces in order to achieve their goals. For example: the pc when installing the software often have a key installation options (eliminating the need to select the installation directory, installation of components, etc.), there is the phone restart function (the shutdown and startup into one operation).
- Facade pattern is to solve the difficulties caused by the use of multiple complex interfaces, simplify user operations played a role
- Schematically illustrates
Appearance Model Application Examples
- Examples of application requirements
- Use the appearance of models to complete home theater project
- Ideas and analysis scheme (FIG class)
public class HomeTheaterFacade {
//定义各个子系统对象
private TheaterLight theaterLight;
private Popcorn popcorn;
private Stereo stereo;
private Projector projector;
private Screen screen;
private DVDPlayer dVDPlayer;
//构造器
public HomeTheaterFacade() {
super();
this.theaterLight = TheaterLight.getInstance();
this.popcorn = Popcorn.getInstance();
this.stereo = Stereo.getInstance();
this.projector = Projector.getInstance();
this.screen = Screen.getInstance();
this.dVDPlayer = DVDPlayer.getInstanc();
}
//操作分成 4 步
public void ready() {
popcorn.on();
popcorn.pop();
screen.down();
projector.on();
stereo.on();
dVDPlayer.on();
theaterLight.dim();
}
public void play() {
dVDPlayer.play();
}
public void pause() {
dVDPlayer.pause();
}
public void end() {
popcorn.off();
theaterLight.bright();
screen.up();
projector.off();
stereo.off();
dVDPlayer.off();
}
}
Analysis of the appearance pattern in the source application framework MyBatis
- The Configuration MyBatis to create objects using MetaObject to skin mode
- + + Source code analysis the Debug schematic
Notes and details of the mode of appearance
- External appearance model details screen subsystem, the appearance of the pattern reduces the complexity of the client subsystem is
- Appearance mode coupling relationship between the client and subsystems - decoupled, so that internal subsystem modules easier to maintain and extend
- By proper use of the appearance mode, you can help us better division level access
- When the system needs to be layered design, consider using the Facade pattern
- While maintaining a legacy of large systems, this system may have become very difficult to maintain and extend, then you can consider developing a new system for the
Facade class, to provide a more clear and simple interface to legacy systems, so that the new system with the Facade class interaction, improve reusability - Not excessive or unreasonable use skin mode, use the facade pattern is good, or directly call good module. To allow the system level, conducive to the maintenance for the purpose.