OC 复合 组装电脑

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OC 复合 组装电脑相关的知识,希望对你有一定的参考价值。

键盘类

#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];

        [email protected]"BENQ";

        self.mouse=mouse;

        

        Keyboard *keyboard=[Keyboard new];

        [email protected]"BENQ";

        self.keyboard=keyboard;

        

        Displayer *displayer=[Displayer new];

        [email protected]"SUMSUN";

        self.displayer=displayer;

        

        Engine *engline=[Engine new];

        [email protected]"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;

        

//        [email protected]"BENQ";

//        [email protected]"BENQ";

//        [email protected]"SUMSUN";

//        [email protected]"Mac mini";

        

        [computer run];

        

    }

    return 0;

}


 

运行结果

技术分享

以上是关于OC 复合 组装电脑的主要内容,如果未能解决你的问题,请参考以下文章

OC-初识面向对象

oc的复合模式

c4d+oc的安装及使用的全过程

华硕主板使用OC引导进BIOS黑屏

LA 3971 组装电脑(二分)

电脑上一些常用的单词有那些