A brief introduction to some simple development patterns in iOS development

Source: Internet
Author: User
Tags mul

Recently the company's work is relatively easy, I want to write some things, because I am doing iOS development, can hope to make more friends in this industry, the following is my common development model, the small examples are to use the OC language, I hope we can put forward views, we have more to communicate.

The following small case is simple Factory mode:

Simple Factory mode:

(1) Calculator Small example

#########

Class of Calculator

#import <Foundation/Foundation.h>

@interface Calutor:nsobject

{

float _num1;

float _num2;

}

@property float NUM1;

@property float num2;

-(float) getresult;

@end

#import "Calutor.h"

@implementation Calutor

-(float) getresult{

float result=0;

return result;

}

@end

##########

#import "Calutor.h"

@interface Plus:calutor

@end

#import "Plus.h"

Addition class

@implementation Plus

-(float) getresult{

float rel=0;

Rel= self.num1+self.num2;

return rel;

}

@end

########

Class of subtraction

#import "Calutor.h"

@interface Jian:calutor

@end

#import "Jian.h"

@implementation Jian

-(float) getresult{

float rel=0;

rel=_num1+_num2;

return rel;

}

@end

########

#import "Calutor.h"

@interface Mul:calutor

@end

#import "Mul.h"

@implementation Mul

-(float) getresult{

float rel=0;

rel=_num1*_num2;

return rel;

}

@end

#######

#import "Calutor.h"

@interface Div:calutor

@end

#import "Div.h"

@implementation Div

-(float) getresult{

float rel=0;

rel=_num1/_num2;

return rel;

}

@end

######

Calculator's factory class

#import <Foundation/Foundation.h>

#import "Jian.h"

#import "Plus.h"

#import "Mul.h"

#import "Div.h"

@interface Calutorfactory:nsobject

+ (calutor*) createoperate: (char) C;

@end

#import "CalutorFactory.h"

@implementation Calutorfactory

+ (calutor*) createoperate: (char) c{

Calutor *cal=nil;

Switch (c) {

Case ' + ':

Cal=[plus new];

Break

Case '-':

Cal=[jian new];

Break

Case ' * ':

Cal=[mul new];

Break

Case '/':

Cal=[div new];

Break

Default

Cal=nil;

Break

}

Return cal;

}

@end

#######

#import <Foundation/Foundation.h>

#import "CalutorFactory.h"

int main (int argc, const char * argv[]) {

@autoreleasepool {

calutor*cal;

Cal=[calutorfactory createoperate: ' + '];

cal.num1=2;

cal.num2=3;

printf ("%.2f\n", [Cal GetResult]);

} return 0;

}

Because OC is a dynamic language, some of the features of object oriented are more pronounced, and the small case is simple Factory mode.

Thank

A brief introduction to some simple development patterns in iOS development

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.