The rational design of the iOS class, object-oriented thinking

Source: Internet
Author: User

Every day updates may have duplicate content, at that time each part of the knowledge point is different, need everyone to read carefully

This article introduces the reasonable design of the iOS class, the object oriented idea


Main.m

#import <Foundation/Foundation.h> #import "Iphone.h" int main (int argc, const char * argv[]) {    Iphone * phone = [Ip Hone new];    Phone->_color = Iphonecolorwhite;    Phone->_size = IPHONESIZE3POINT5;        Phone = 0ffxxx    //[0ffxxx camerawithflashlightstatus];    [Phone camerawithflashlightstatus:iphoneflashlightstatusopen];        return 0;}



Iphone.h

@interface iphone:nsobject{    @public    /** used to store Iphone screen size *    ///enum iphonesize and iphonesize equivalents    Iphonesize _size;//used to store iphone screen size    /** used to store iphone color */    iphonecolor _color;//used to store iphone color        /** used to store CPU size */    float _cpu;    /** used to store internal capacity */    float _ram;} Design techniques, assuming that the method does not return a value, do not tangle whether there is a return value, do not let trivial things interfere with the idea/** open flash */-(void) openflashlight;/** turn off Flash */-(void) closeflashlight;/** Auto */-(void) flaselightauto;/** photo */-(void) Camerawithflashlightstatus: (iphoneflashlightstatus) flaselightstatus;@ End



Iphone.m

#import "Iphone.h" @implementation iphone/** open Flash */-(void) openflashlight{    NSLog (@ "Turn on Flash");} /** off Flash */-(void) closeflashlight{    NSLog (@ "Off Flash");} /** auto */-(void) flaselightauto{    NSLog (@ "auto mode");} /** photo */-(void) Camerawithflashlightstatus: (iphoneflashlightstatus) flaselightstatus{    //The inside of the class how to get an object address    / /self keyword    //WHO calls self on behalf of who    if (flaselightstatus = = Iphoneflashlightstatusopen)    {        //Open flash        [self Openflashlight];    }    else if (flaselightstatus = = Iphoneflashlightstatusclose)    {        [self closeflashlight];        Turn off the Flash    }    else    {        [self flaselightauto];        Auto mode    }        NSLog (@ "Take a picture! Laugh a "); @end



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The rational design of the iOS class, object-oriented thinking

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.