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