@fiy-fish
2015-07-18T19:50:49.000000Z
字数 926
阅读 1245
Objective-c
// main.m
// 类簇
//
// Created by Aaron on 15/7/8.
// Copyright (c) 2015年 Aaron. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Shape.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Shape *shape = [Shape createShapeWithType:kShapeYX];
NSLog(@"%@",shape);
[shape draw];
NSString *str = [NSString stringWithContentsOfFile:@"/users/qianfeng/desktop/file1.txt" encoding:NSUTF8StringEncoding error:nil];
}
return 0;
}
#import <Foundation/Foundation.h>
typedef enum
{
kShapeSJX,
kShapeZFX,
kShapeYX
}ShapeType;
@interface Shape : NSObject
{
NSString *_name;
}
+(instancetype)createShapeWithType:(ShapeType)type;
-(void)draw;
@end
#import "Shape.h"
#import "ShapeSJX.h"
#import "ShapeYX.h"
#import "ShapeZFX.h"
@implementation Shape
+(instancetype)createShapeWithType:(ShapeType)type
{
NSArray *array = @[[ShapeSJX class],[ShapeZFX class],[ShapeYX class]];
Shape *s = [[array[type] alloc] init];
return s;
}
-(NSString *)description
{
return _name;
}
-(void)draw
{
NSLog(@"....");
}
@end