Ii. Appearance Mode
The appearance mode provides an interface for his subsystem to make it more usable. When using the appearance mode, you only need a small amount of code to provide classes in a typical Class Library without any modifier usage. An appearance is a class, which contains functions between the Toolkit and the complete application, providing a simple usage for the Toolkit or subsystem class.
Appearance, tool, and example
The appearance class method may be a static method. In this case, the appearance class is called a tool class in UML. An example class is an example of how to use a class or subsystem. There are many advantages that the appearance class can provide, and the example class can also provide. The appearance class may belong to the class library, but the instance class must not belong to the class library. Www.2cto.com
In the process of software development, the program is generally larger and larger, and the impact of classes and subsystems in the system will make the relationship between each other more complicated, that is, excessive coupling, this leads to a change in the associated subsystems or classes as the classes or subsystems in the system change.
Example
Power supply Switch
For ease of use, a power switch can control the startup and shutdown of two lights, an air conditioner, and a TV. The power supply switch can control all the above electrical equipment at the same time and design the system in appearance mode.
The appearance mode aims to reduce the complexity of the system.
The appearance mode greatly improves the ease of use of the client, so that the client does not need to care about the details of the sub-system, and relevant functions can be called through the appearance role.
Appearance mode instance and Analysis
Take the computer loading and shutdown process as an example.
Subsystem role: CPU, memory, and hard disk.
Appearance role: computer.
Customer: user.
Dependencies between them:
The following describes the specific implementation.
(1) CPU. java defines the functions for starting and disabling the CPU.
CPU. java
[Java]
Package structure. facade;
Public class CPU {
Public void startup (){}
Public void shutdown (){}
}
(2) Memory-class Memory. java defines the function for loading and clearing the Memory.
Memory class Memory. java
[Java]
Package structure. facade;
Public class Memory {
Public void startup (){}
Public void shutdown (){}
}
(3) hard Disk. java defines the function for loading and detaching hard disks.
Hard Disk. java
[Java
Package structure. facade;
Public class Disk {
Public void startup (){}
Public void shutdown (){}
}
(4) Appearance mode Computer. java contains three class objects: CPU, memory, and hard disk. It defines functions for starting and disabling computers, and starts and disables CPU, memory, and hard disks in batches at startup and shutdown.
Appearance mode Computer. java
[Java]
Package structure. facade;
/* Appearance mode */
Public class Computer {
Private CPU cpu = new CPU ();.......
// Declare the object
Public void startup () {// method of calling the object}
Public void shutdown () {// method of calling the object}
}
(5) For User. java, we only need to call the functions of Computer. java to start and shut down the Computer, instead of loading and disabling the CPU, memory, and hard disk in sequence.
User. java
[Java]
Package structure. facade;
Public class User {
Public static void main (String args []) {
Computer computer = new Computer ();
Computer. startup (); // call
Computer. shutdown ();
}
}
Summary:
It can be seen from the program that a Computer appearance class can be used to control all components of the Computer without having to control all its components separately. This is the role of the appearance mode.