OBJECTIVE-C Composite (combination)

Source: Internet
Author: User

  

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)

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.