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

Source: Internet
Author: User

Things that are updated every day may have recurring content. At that time, each part of the knowledge point is different, we need to read carefully

The proper design of the iOS class is described here. Object Oriented thinking


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, if the method does not return 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;/** Own active */-(void) flaselightauto;/** photograph */-(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");} /** own initiative */-(void) flaselightauto{    NSLog (@ "own active 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];        Own active mode    }        NSLog (@ "took photos.) Laugh a "); @end



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.