iOS類的合理設計,物件導向思想

來源:互聯網
上載者:User

標籤: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類的合理設計,物件導向思想

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.