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