iOS design mode-Abstract factory

Source: Internet
Author: User

iOS design mode-Abstract factory

Schematic diagram

Description

1. Abstract factory refers to the provision of an interface that creates a series of related or interdependent objects without specifying their specific classes

2. If multiple classes have the same behavior, but the actual implementation is different, it may be necessary for an abstract type to be inherited as its parent class, which defines the common behavior that all related concrete classes will share.

Source

Https://github.com/YouXianMing/AbstractFactoryPattern

////BrandingFactory.h//Abstractfactorypattern////Created by youxianming on 15/8/2.//Copyright (c) 2015 youxianming. All rights reserved.//#import<Foundation/Foundation.h>#import<UIKit/UIKit.h>@interfaceBrandingfactory:nsobject/** * Abstract Factory Method * * @return Specific factory*/+ (Brandingfactory *) factory;/** * Brandedview produced by the Factory (constructed by the specific factory) * * @return production of good Brandedview*/-(UIView *) Brandedview;/** * Brandedmainbutton produced by the Factory (constructed by the specific factory) * * @return production of good Brandedmainbutton*/-(UIButton *) Brandedmainbutton;@end
////brandingfactory.m//Abstractfactorypattern////Created by youxianming on 15/8/2.//Copyright (c) 2015 youxianming. All rights reserved.//#import "BrandingFactory.h"#import "AcmeBrandingFactory.h"#import "SierraBrandingFactory.h"@implementationbrandingfactory+ (Brandingfactory *) Factory {if([[Selfclass] Issubclassofclass:[acmebrandingfactoryclass]]) {                return[AcmebrandingfactoryNew]; } Else if([[Selfclass] Issubclassofclass:[sierrabrandingfactoryclass]]) {            return[SierrabrandingfactoryNew]; } Else {            returnNil; }}-(UIView *) Brandedview {returnNil;}-(UIButton *) Brandedmainbutton {returnNil;}@end
// //   AcmeBrandingFactory.h//  abstractfactorypattern / ///  Created by youxianming on 15/8/2. //   Copyright (c) 2015 youxianming. All rights reserved. // #import " BrandingFactory.h " @interface acmebrandingfactory:brandingfactory @end
////acmebrandingfactory.m//Abstractfactorypattern////Created by youxianming on 15/8/2.//Copyright (c) 2015 youxianming. All rights reserved.//#import "AcmeBrandingFactory.h"@implementationacmebrandingfactory-(UIView *) Brandedview {NSLog (@"Acmebrandedview"); returnNil;}-(UIButton *) Brandedmainbutton {NSLog (@"Acmebrandedmainbutton"); returnNil;}@end
// //   SierraBrandingFactory.h//  abstractfactorypattern/ ///   Created by youxianming on 15/8/2. //   Copyright (c) 2015 youxianming. All rights reserved. // #import " BrandingFactory.h " @interface sierrabrandingfactory:brandingfactory @end
////sierrabrandingfactory.m//Abstractfactorypattern////Created by youxianming on 15/8/2.//Copyright (c) 2015 youxianming. All rights reserved.//#import "SierraBrandingFactory.h"@implementationsierrabrandingfactory-(UIView *) Brandedview {NSLog (@"Sierrabrandedview"); returnNil;}-(UIButton *) Brandedmainbutton {NSLog (@"Sierrabrandedmainbutton"); returnNil;}@end

Analysis

Schematic diagram of the relationship

iOS design mode-Abstract factory

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.