码迷,mamicode.com
首页 > 其他好文 > 详细

OC 复合 组装电脑

时间:2016-03-01 20:36:26      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:

键盘类

#import <Foundation/Foundation.h>

 @interface Keyboard : NSObject

@property(strong,nonatomic)NSString *brand;

@end

 

#import "Keyboard.h"

@implementation Keyboard

- (NSString *)description

{

    return [NSString stringWithFormat:@"%@", _brand];

}

@end


鼠标类

#import <Foundation/Foundation.h>

 @interface Mouse : NSObject

@property(strong,nonatomic)NSString *brand;

@end

 

#import "Mouse.h"

 @implementation Mouse

- (NSString *)description

{

    return [NSString stringWithFormat:@"%@", _brand];

}

@end


显示屏类

#import <Foundation/Foundation.h>

 @interface Displayer : NSObject

@property(strong,nonatomic)NSString *brand;

@end

 

#import <Foundation/Foundation.h>

 @interface Displayer : NSObject

@property(strong,nonatomic)NSString *brand;

@end


机箱类 

#import <Foundation/Foundation.h>

 @interface Engine : NSObject

@property(strong,nonatomic)NSString *brand;

@end

 

#import "Engine.h"

 @implementation Engine

- (NSString *)description

{

    return [NSString stringWithFormat:@"%@", _brand];

}

@end


 

电脑类

#import <Foundation/Foundation.h>

#import "Keyboard.h"

#import "Mouse.h"

#import "Displayer.h"

#import "Engine.h"

@interface Computer : NSObject

@property(strong,nonatomic)Mouse *mouse;

@property(strong,nonatomic)Keyboard *keyboard;

@property(strong,nonatomic)Displayer *displayer;

@property(strong,nonatomic)Engine *engline;

 

-(void)run;

@end

 

#import "Computer.h"

#import "Keyboard.h"

#import "Mouse.h"

#import "Displayer.h"

#import "Engine.h"

@implementation Computer

 

- (instancetype)init

{

    self = [super init];

    if (self) {

        Mouse *mouse= [[Mouse alloc] init];

        mouse.brand=@"BENQ";

        self.mouse=mouse;

        

        Keyboard *keyboard=[Keyboard new];

        keyboard.brand=@"BENQ";

        self.keyboard=keyboard;

        

        Displayer *displayer=[Displayer new];

        displayer.brand=@"SUMSUN";

        self.displayer=displayer;

        

        Engine *engline=[Engine new];

        engline.brand=@"Mac mini";

        self.engline=engline;

 

    }

    return self;

}

-(void)run

{

    NSLog(@"%@",[_mouse description]);

    NSLog(@"%@",[_keyboard description]);

    NSLog(@"%@",[_displayer description]);

    NSLog(@"%@",[_engline description]);

}

@end


 

main 函数

#import <Foundation/Foundation.h>

#import "Computer.h"

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

    @autoreleasepool {

        Computer *computer=[[Computer alloc] init];

//        Keyboard *keyboard=[[Keyboard alloc] init];

//        Mouse *mouse=[[Mouse alloc] init];

//        Engine *engline=[[Engine alloc] init];

//        Displayer *displary=[[Displayer alloc] init];

//        

//        computer.mouse=mouse;

//        computer.keyboard=keyboard;

//        computer.engline=engline;

//        computer.displayer=displary;

        

//        mouse.brand=@"BENQ";

//        keyboard.brand=@"BENQ";

//        displary.brand=@"SUMSUN";

//        engline.brand=@"Mac mini";

        

        [computer run];

        

    }

    return 0;

}


 

运行结果

技术分享

OC 复合 组装电脑

标签:

原文地址:http://www.cnblogs.com/bolin-123/p/5232118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!