Compounding : Combining multiple components together to form a whole and then work with the whole, which is called a compositeThe overall function is more powerful after compounding
Write a house class, composed of doors, windows and so on, doors and windows have their own switch method, and then the door and window these compound together called House Class call House class in and out method actually call to door switch call House ventilation method, actually call to window switch
// A large class consisting of objects of multiple classes is a combined process #import <Foundation/Foundation.h>"Widow.h" "Door.h" * *widow ; -(void) inouthouse; -(void) exchangair; @end
#import"House.h"@implementation House-(void) inouthouse{[_door Open]; NSLog (@"into the house"); [_door Close]; NSLog (@"out of the house");}-(void) exchangair{[_widow Open]; NSLog (@"start breathing ."); [_widow Close]; NSLog (@"Ventilation End");} @end
#import <Foundation/Foundation.h>
@interface widow:nsobject -( void ) Open;
-(void ) close; @end #import Span style= "color: #800000;" > " widow.h "
@implementation widow -(void ) open{NSLog ( @ " windows " );
-(void ) close{NSLog ( Span style= "color: #800000;" >@ " close window "
#import <Foundation/Foundation.h>@interface Door:nsobject-(void) Open;-(void) close; @end #import"Door.h"@implementation Door-(void) open{NSLog (@"Open");}-(void) close{NSLog (@"closing");} @end
#import <Foundation/Foundation.h>"House.h"int main (int ConstChar * argv[]) { @autoreleasepool { *h=[[House alloc]init]; H.door=[[Door alloc]init]; H.widow=[[widow Alloc]init]; [H Inouthouse]; [H Exchangair]; } return 0 ;}
OBJECTIVE-C Composite (combination)