zoukankan      html  css  js  c++  java
  • iOS类的合理设计,面向对象思想

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

    这里介绍了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
    



  • 相关阅读:
    Vim深入研究
    信息安全系统设计基础第十三周学习总结——20135308
    信息安全系统设计基础实验五:通讯协议设计
    信息安全系统设计基础第十二周学习总结 ——20135308
    信息安全系统设计基础实验四:外设驱动程序设计
    信息安全系统设计基础实验三:实时系统的移植
    GDB深入研究——20135308芦畅
    信息安全系统设计基础第十一周学习总结——20135308
    第九次ScrumMeeting博客
    第八次ScrumMeeting博客
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7219267.html
Copyright © 2011-2022 走看看