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