保姆照顾孩子版本1

Main.m

#import "Children.h"
#import "Nure.h"
#import "Nanny.h"

int main(int argc, const char * argv[])
{

    Children *children = [[Children alloc] init];
//    Nure *nure = [[Nure alloc] init];
    Nanny *nanny = [[Nanny alloc] init];
    
//    [children setNure:nure];
    [children setNanny:nanny];
    
    
    [[NSRunLoop currentRunLoop] run];
    
    return 0;
}

Children.h

@class Nure;
@class Nanny;

@interface Children : NSObject {

    NSInteger _index;
    Nure *_nure;
    Nanny *_nanny;
    
}

- (void)setNure:(Nure *)nure;
- (void)setNanny:(Nanny *)nanny;

Children.m

#import "Nure.h"
#import "Nanny.h"

@implementation Children

- (id)init {

    self = [super init];
    
    if (self ) {
        //开启定时器
        [NSTimer scheduledTimerWithTimeInterval:1
                                         target:self
                                       selector:@selector(timeAction:)userInfo:nil
                                        repeats:YES];
    }
    
    return self;
}

- (void)setNure:(Nure *)nure {

    _nure = nure;
}

- (void)setNanny:(Nanny *)nanny {

    _nanny = nanny;
    
}

- (void)timeAction:(NSTimer *)time {

    _index ++;
    
    if (_index == 5) {
        //小孩脏了
//        [_nure wash:self];
        [_nanny wash:self];
    }
    
    if (_index == 10) {
        //小孩不高兴了
//        [_nure play:self];
        [_nanny play:self];
    }
    
}


Nanny.h

#import "Children.h"

@interface Nanny : NSObject

//洗澡
- (void)wash:(Children *)child;

//和小孩玩
- (void)play:(Children *)child;

Nanny.m

@implementation Nanny

//洗澡
- (void)wash:(Children *)child {
    
    NSLog(@"护士给小孩洗澡了");
    
}

//和小孩玩
- (void)play:(Children *)child {
    
    NSLog(@"护士和小孩玩耍");
    
}

Nurse.h

#import "Children.h"

@interface Nure : NSObject

//洗澡
- (void)wash:(Children *)child;

//和小孩玩
- (void)play:(Children *)child;

Nurse.m

//洗澡
- (void)wash:(Children *)child {

    NSLog(@"保姆给小孩洗澡了");
    
}

//和小孩玩
- (void)play:(Children *)child {

    NSLog(@"保姆和小孩玩耍");
    
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值