模式 / 结构模式
image

//Subject
@interface Graphic : NSObject
@property (nonatomic, copy) NSString *fileName;

- (instancetype)initWithFileName:(NSString *)fileName;
- (void)draw;
- (NSString *)getFileName;
@end

@implementation Graphic

- (instancetype)initWithFileName:(NSString *)fileName {
    self = [super init];
    if (self) {
        _fileName = [fileName copy];
    }
    return self;
}

- (void)draw {
    NSLog(@"base draw");
}

- (NSString *)getFileName {
    return self.fileName;
}
@end

//RealSubject
@interface Image : Graphic
@end

@implementation Image
//Request()
- (void)draw {
    [super draw];
    NSLog(@"draw %@"self.fileName);
}
@end

//Proxy
@interface ImageProxy : Graphic
- (Image *)getImage;
@end

@implementation ImageProxy {
    Image *_image;
}

- (void)draw {
    [[self getImage] draw];
}

- (Image *)getImage {
    if (_image == nil) {
        _image = [[Image alloc] initWithFileName:self.fileName];
    }
    return _image;
}
@end

//Client
ImageProxy *proxy = [[ImageProxy alloc] initWithFileName:@"1.png"];
//operation without creating a RealSubject
NSString *fileName = [proxy getFileName];
//forwarded to the RealSubject
[proxy draw];
//printed: base draw
//         draw 1.png

NSLog(@"fileName is %@", fileName);


Provide a surrogate or placeholder for another object to control access to it. The proxy implements the interface of the original object.