iOS design mode-commands

Source: Internet
Author: User

iOS design mode-commands

Schematic diagram

Description

The Command object encapsulates information about how the instruction is executed against the target, so the client or caller does not have to know any details of the target, but can still perform any existing operations on him. By encapsulating the request into an object, the client can parameterize it and place it in a queue or log, and can support a revocable operation. The command object binds one or more actions to a specific sink. The command pattern eliminates the binding between the action as an object and the receiver that executes it.

  invoker.h//  commandpattern////  Created by youxianming on 15/10/17.//  Copyright? 2015 Youxianming. All rights reserved.//#import <Foundation/Foundation.h> #import "CommandProtocol.h" @interface invoker:nsobject /** *  Single Example * *  @return Singleton */+ (instancetype) sharedinstance;/** *  Add and Execute * *  @param command command */-(void) Addan Dexecute: (id <CommandProtocol>) command; @end
  invoker.m//  commandpattern////  Created by youxianming on 15/10/17.//  Copyright? 2015 Youxianming. All rights reserved.//#import "Invoker.h" @interface Invoker () @property (nonatomic, strong) Nsmutablearray * Commandqueue, @end @implementation invoker+ (instancetype) sharedinstance {    static Invoker        * Sharedinstancevalue = nil;    Static dispatch_once_t oncepredicate;        Dispatch_once (&oncepredicate, ^{                sharedinstancevalue = [[Invoker alloc] init];        Sharedinstancevalue.commandqueue = [Nsmutablearray array];    });        return sharedinstancevalue;} -(void) Addandexecute: (id <CommandProtocol>) command {    //Add and Execute    [Self.commandqueue addobject:command ];    [Command execute];} @end
  commandprotocol.h//  commandpattern////  Created by youxianming on 15/10/17.//  Copyright? 2015 Youxianming. All rights reserved.//#import <Foundation/Foundation.h> @protocol commandprotocol <NSObject> @required/** *  execute command */-(void) execute; @end

Details

iOS design mode-commands

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.