码迷,mamicode.com
首页 > 移动开发 > 详细

iOS类的合理设计,面向对象思想

时间:2017-07-21 19:54:31      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:data-   地址   bottom   ase   pen   HTST   top   屏幕   关闭   

每天更新的东西可能有反复的内容。当时每一部分的知识点是不同的,须要大家认真阅读

这里介绍了iOS类的合理设计。面向对象思想


main.m

#import <Foundation/Foundation.h>
#import "Iphone.h"
int main(int argc, const char * argv[])
{
    Iphone * phone = [Iphone new];
    phone->_color = IphoneColorWhite;
    phone->_size = IphoneSize3point5;
    
    //phone = 0ffxxx
    //[0ffxxx cameraWithFlashLightStatus];
    [phone cameraWithFlashLightStatus:IphoneFlashLightStatusOpen];
    
    return 0;
}



iphone.h

@interface Iphone : NSObject
{
    @public
    /** 用来存储iPhone屏幕尺寸 */
    //enum IphoneSize 与IphoneSize 等价
    IphoneSize _size;//用来存储iPhone屏幕尺寸
    /** 用来存储iPhone颜色 */
    IphoneColor _color;//用来存储iPhone颜色
    
    /** 用来存储cpu大小 */
    float _cpu;
    /** 用来存储内部容量大小 */
    float _ram;
}

//设计方法技巧,如果方法没有返回值,不要纠结是否有返回值,不要让琐碎的事儿干扰思路
/**打开闪光灯*/
-(void)openFlashLight;
/**关闭闪光灯*/
-(void)closeFlashLight;
/**自己主动*/
-(void)flaseLightAuto;
/**拍照*/
-(void) cameraWithFlashLightStatus:(IphoneFlashLightStatus)flaseLightStatus;

@end



iphone.m

#import "Iphone.h"

@implementation Iphone
/**打开闪光灯*/
- (void)openFlashLight
{
    NSLog(@"打开闪光灯");
}
/**关闭闪光灯*/
- (void)closeFlashLight
{
    NSLog(@"关闭闪光灯");
}
/**自己主动*/
-(void)flaseLightAuto
{
    NSLog(@"自己主动模式");
}
/**拍照*/
- (void)cameraWithFlashLightStatus:(IphoneFlashLightStatus)flaseLightStatus
{
    //类的内部怎样获得一个对象的地址
    //self keyword
    //谁调用 self就代表谁
    if(flaseLightStatus == IphoneFlashLightStatusOpen)
    {
        //打开闪光灯
        [self openFlashLight];
    }
    else if(flaseLightStatus == IphoneFlashLightStatusClose)
    {
        [self closeFlashLight];
        //关闭闪光灯
    }
    else
    {
        [self flaseLightAuto];
        //自己主动模式
    }
    
    NSLog(@"拍照了。笑一个");
}
@end



iOS类的合理设计,面向对象思想

标签:data-   地址   bottom   ase   pen   HTST   top   屏幕   关闭   

原文地址:http://www.cnblogs.com/gccbuaa/p/7219267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!