OC Composite Assembly Computer

Source: Internet
Author: User

Keyboard class

#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

Mouse class

#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

Display class

#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

Chassis class

#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

Computer class

#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 function

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

}

Run results

OC Composite Assembly Computer

Related Article

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.