Abstract Factory of IOS design mode

Source: Internet
Author: User
Tags uikit

Design patterns are an essential knowledge of program promotion, and here's how iOS implements abstract factory design patterns. This article is a look at the OC programming of the Abstract factory this chapter after writing, if you do not understand the principle can look at the book.

TestView.h first create a view

  testview.h//  abstractfactory////  Created by du Jia Li on 11/10/14.//  Copyright (c) 2014 DuPont. All rights reserved.//#import <UIKit/UIKit.h> @interface testview:uiview@end

testview.m

  testview.m//  abstractfactory////  Created by du Jia Li on 11/10/14.//  Copyright (c) 2014 DuPont. All rights reserved.//#import ' TestView.h ' @implementation testview-(ID) initWithFrame: (cgrect) frame{    if (self = [ Super Initwithframe:frame]) {        Self.backgroundcolor = [Uicolor redcolor];            }    return self;} @end

Next, create two classes testfactory, testbrandingfactory whichTestfactory inherits Testbrandingfactory. The specific implementation is as follows:

TestBrandingFactory.h

  testbrandingfactory.h//  abstractfactory////  Created by du Jia Li on 11/10/14.//  Copyright (c) 2014 DuPont. All rights reserved.//#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface testbrandingfactory:nsobject+ (Testbrandingfactory *) factory;-(UIView *) Createtestview: (CGRect) frame; @end

Testbrandingfactory.m

  testbrandingfactory.m//  abstractfactory////  Created by du Jia Li on 11/10/14.//  Copyright (c) 2014 DuPont. All rights reserved.//#import "TestBrandingFactory.h" #import "TestFactory.h" @implementation testbrandingfactory+ ( Testbrandingfactory *) factory{    return [[Testfactory alloc] init];} -(UIView *) Createtestview: (cgrect) frame{    return nil;} @end

TestFactory.h

  testfactory.h//  abstractfactory////  Created by du Jia Li on 11/10/14.//  Copyright (c) 2014 DuPont. All rights reserved.//#import "TestBrandingFactory.h" @interface testfactory:testbrandingfactory@end

Testfactory.m

  testfactory.m//  abstractfactory////  Created by du Jia Li on 11/10/14.//  Copyright (c) 2014 DuPont. All rights reserved.//#import "TestFactory.h" #import "TestView.h" @implementation testfactory-(UIView *) Createtestview: (cgrect) frame{    return [[TestView alloc] initwithframe:frame];} @end

Finally post the implementation

Testbrandingfactory * tmp = [testbrandingfactory factory];    UIView *v = [tmp createtestview:cgrectmake (+, +, +)];    [Self.view Addsubview:v];



















Abstract Factory of IOS design mode

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.