Objective-c design mode-appearance faced (interface adaptation)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.