• 延展性,实现方法的私有化


    //Study.m文件声明

    1 #import <Foundation/Foundation.h>
    2 
    3 @interface Study : NSObject
    4 
    5 -(void)study; 
    6 
    7 @end

    //Study.h文件实现

     1 #import "Study.h"
     2 
     3 @interface Study ()//偷偷声明
     4 
     5 -(void)playLOL;
     6 
     7 -(void)playCF;
     8 
     9 @end
    10 
    11 @implementation Study
    12 
    13 -(void)study
    14 
    15 {
    16     NSLog(@"我正在学习");
    17 
    18     [self playCF];
    19 
    20     [self playLOL];
    21 
    22 }
    23 
    24 -(void)playLOL//延展1
    25 
    26 {
    27     NSLog(@"我同样在玩LOL");
    28 }
    29 
    30 -(void)playCF//延展2
    31 
    32 {
    33     NSLog(@"我还在玩CF");
    34 }
    35 
    36 @end

     //main.m文件中

    Study *xiaoming=[[Study alloc]init];
    
    [xiaoming study];
    

    //

    2015-11-10 18:53:47.972 test[7322:112328] 我正在学习
    2015-11-10 18:53:47.972 test[7322:112328] 我在玩CF
    2015-11-10 18:53:47.972 test[7322:112328] 我在玩LOL
    

      

      

  • 相关阅读:
    ruby学习笔记(5)
    rails学习笔记(2)
    一个不错的rails2.0教程
    rails学习笔记(2)
    rails学习笔记(1)
    一个不错的rails2.0教程
    ruby学习笔记(6)
    ruby学习笔记(6)
    rails学习笔记(1)
    DELPHI的编译指令
  • 原文地址:https://www.cnblogs.com/liuyingjie/p/4953978.html
Copyright © 2020-2023  润新知