Appearance mode
The design pattern is the same as the adapter, but it has a different granularity to the object control, and the adapter generally controls the docking of a system and client. The façade is used to abstract multiple systems working together.
Appearance generally has multiple subsystems, so the appearance should hold multiple subsystems of reference, isomorphic to the upper layer to provide an abstract interface implementation encapsulation. Appearance is generally can be used multiple times, such as a large system, you can use the appearance of many times to encapsulate, and then the appearance of using the appearance of encapsulation to achieve multi-layered abstraction.
Usage Scenarios
Subsystems are becoming increasingly complex. Many classes evolve in the process of applying patterns. You can use skins to provide a simpler interface for these subsystem classes.
You can use the appearance to layer the child system. Each subsystem level has an appearance as an entry point. Allowing them to communicate through their appearance simplifies their dependencies.
Demo
Because it is also the interface adaptation, but the application scenario is different, the difference is not very large, it is not described in detail.
Using a taxi scene to simulate the appearance pattern, the presence of the driver and the price of the two systems, with the faced package, provide
Drivetolocation: interface
#import<Foundation/Foundation.h>@interfaceTaximeter:nsobject-(void) Start;-(void) stop;@end#import "Taximeter.h"@implementationtaximeter-(void) start{NSLog (@"%@", Nsstringfromselector (_cmd));}-(void) stop{NSLog (@"%@", Nsstringfromselector (_cmd));}@end#import<Foundation/Foundation.h>@interfaceCar:nsobject-(void) Releasebrakes;-(void) Changegears;-(void) Pressaccelerator;-(void) Pressbrakes;-(void) Releaseaccelerator;@end#import "Car.h"@implementationCar-(void) releasebrakes{NSLog (@"%@", Nsstringfromselector (_cmd));}-(void) changegears{NSLog (@"%@", Nsstringfromselector (_cmd));}-(void) pressaccelerator{NSLog (@"%@", Nsstringfromselector (_cmd));}-(void) pressbrakes{NSLog (@"%@", Nsstringfromselector (_cmd));}-(void) releaseaccelerator{NSLog (@"%@", Nsstringfromselector (_cmd));}@end
Faced
#import<Foundation/Foundation.h>@interfaceFaced:nsobject-(void) Drivetolocation: (cgpoint) x;@end#import "Faced.h"#import "Taximeter.h"#import "Car.h"@implementationfaced-(void) Drivetolocation: (cgpoint) x{taximeter*meter = [TaximeterNew]; [Meter start]; Car*car = [carNew]; [Car releasebrakes]; [Car changegears]; [Car pressaccelerator]; [Car releaseaccelerator]; [Car pressbrakes]; [meter stop];}@end
Clients and Results
[[FacedNew] Drivetolocation:cgpointzero]; -- -- - One: .:38.004faced[656:20064] Start -- -- - One: .:38.005faced[656:20064] Releasebrakes -- -- - One: .:38.005faced[656:20064] Changegears -- -- - One: .:38.006faced[656:20064] Pressaccelerator -- -- - One: .:38.006faced[656:20064] Releaseaccelerator -- -- - One: .:38.006faced[656:20064] Pressbrakes -- -- - One: .:38.006faced[656:20064] Stop
Objective-c design mode-appearance faced (interface adaptation)