iOS design mode-prototypes

Source: Internet
Author: User

iOS design mode-prototypes

Schematic diagram

Description

1. prototype mode to copy the prototype and create a new object

2. The differences between instances of different classes are only a few combinations of States, so copying prototypes is more convenient than manual instantiation

3. Class is not easy to create, each component can use other components as a sub-node of the composite object, copying the existing composite object is easier than the copy modification

Source

Https://github.com/YouXianMing/PrototypePattern

////BaseCopyObject.h//Prototypepattern////Created by youxianming on 15/7/29.//Copyright (c) 2015 youxianming. All rights reserved.//#import<Foundation/Foundation.h>@interfaceBasecopyobject:nsobject <NSCopying>/** * ==> subclass do not override this method <== * * Copy operation * * @param zone * * @return newly copied objects*/- (ID) Copywithzone: (Nszone *) zone;/** * ==> overrides <== * * Parameter Assignment operation * * @param object for basecopyobject copy operation*/- (void) Parameterscopyoperationwithbasecopyobject: (Basecopyobject *) Basecopyobject;@end
////BASECOPYOBJECT.M//Prototypepattern////Created by youxianming on 15/7/29.//Copyright (c) 2015 youxianming. All rights reserved.//#import "BaseCopyObject.h"@implementationBasecopyobject- (ID) Copywithzone: (Nszone *) Zone {basecopyobject*copy = [Selfclass] Allocwithzone:zone];        [Self parameterscopyoperationwithbasecopyobject:copy]; returncopy;}- (void) Parameterscopyoperationwithbasecopyobject: (Basecopyobject *) Basecopyobject {//overridden by subclasses}@end

Analysis

The abstract base class follows the replication protocol and implements the basic replication functionality

Instantiated classes inherit the replication functionality by inheriting the abstract base class

* Make a deep copy of the dictionary and array

* The array and dictionary have completed a deep copy

The objects in the array (or objects in the dictionary) are required to implement the Nscopying protocol when implementing the copy, or they can inherit the base class that implements the Nscopying protocol.

iOS design mode-prototypes

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.