Objective-c appearance Mode--Simple introduction and use

Source: Internet
Author: User

Appearance mode (facade), which provides a consistent interface for a set of interfaces in a subsystem, defines a high-level interface that makes this subsystem easier to use.

You can consider using the appearance mode in the following cases: (1) The initial stage of the design should be conscious of separating the different layers and establishing the appearance pattern between the layers and the layers. (2) During the development stage, the subsystem becomes more and more complex, and the appearance mode is added to provide a simple calling interface. (3) When maintaining a large legacy system, it is possible that the system is very difficult to maintain and extend, but it also contains very important features for it to develop an appearance class so that the new system interacts with it. A little: (1) The loosely coupled relationship between the subsystem and the client is realized. (2) The client shields the subsystem components, reduces the number of objects that the client needs to process, and makes the subsystem easier to use. Simple code example: Create a new group containing ' SHAPE.H/SHAPE.M/RECTSHAPE.H/RECTSHAPE.M/CIRCLESHAPE.H/CIRCLESHAPE.M Shape.h
1 #import <Foundation/Foundation.h>23@interface  shape:nsobject 4 5 -(void) draw; 6 7 @end

RectShape.h

1 #import " Shape.h " 2 3 @interface Rectshape:shape 4 5 -(void) draw; 6 7 @end

CircleShape.h

1 #import " Shape.h " 2 3 @interface Rectshape:shape 4 5 -(void) draw; 6 7 @end

Create another DRAWSHAPE.H/DRAWSHAPE.M to use as a controller

1 #import<Foundation/Foundation.h>2 #import "RectShape.h"3 #import "CircleShape.h"4 5 @interfaceDrawshape:nsobject6 7+ (void) Drawrectshape;8+ (void) Drawcircleshape;9 Ten @end

Used in controller

1 #import "ViewController.h"2 #import "DrawShape.h"3 4 @interfaceViewcontroller ()5 6 @end7 8 @implementationViewcontroller9 Ten- (void) Viewdidload { One [Super Viewdidload]; A      -     //Invoke Draw Interface - [Drawshape Drawrectshape]; the [Drawshape Drawcircleshape]; -      - } -  +  - @end

Objective-c appearance Mode--Simple introduction and use

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.