Design and Implementation of Electronic menus for IOS development (inheritance, encapsulation, and polymorphism)

Source: Internet
Author: User

Design and Implementation of Electronic menus for IOS development (inheritance, encapsulation, and polymorphism)

//// Main. m // electronic menu // # import
 
  
# Import Food. h # import CoolFood. h # import HotFood. h # import MainFood. h # import Drinks. h # import BillBoard. hint main (int argc, const char * argv []) {Food * food = [[Food alloc] init]; [food showInformation: @ braised pork andShowMaterial: @ pork ginger garlic andShowNurition: @ calcium, iron, and zinc new vitamins]; NSLog (% @, food); @ autoreleasepool {// insert code here... NSLog (@ Hello, World !); } Return 0 ;}
 
/// Menu. h // electronic Menu // # import
 
  
# Import Food. h # import CoolFood. h # import HotFood. h # import MainFood. h # import Drinks. h # import BillBoard. h @ interface Menu: NSObject {/** used to record the order quantity */int _ recordOfFood;/** used to record the order status */BOOL _ statusOfFood; /** used to record Food prices */int _ priceOfFood;}-(void) showInformation :( food *) Food; @ end
 
//// Menu. m // electronic Menu // # import Menu. h @ implementation Menu-(void) showInformation :( Food *) food {if ([food isKindOfClass: [CoolFood class]) {CoolFood * cool = (CoolFood *) food; [cool show];} else if ([food isKindOfClass: [HotFood class]) {HotFood * hot = (HotFood *) food; [hot show];} else if ([food isKindOfClass: [MainFood class]) {MainFood * mainFood = (MainFood *) food; [mainFood show];} else {Drinks * drinks = (Drinks *) food; [drinks show] ;}}@ end

// Food. h // electronic menu /// * you can use the inherited electronic menu Implementation 1. Food category */# import
 
  
@ Interface Food: NSObject {/** is used to record the Dish name */NSString * _ foodName;/** composition material */NSString * _ material; /** nutrition information */NSString * _ nutrition;/** used to record the food type */NSString * _ kindOfFood;} @ property NSString * foodName; @ property NSString * material; @ property NSString * nutrition; @ property NSString * kindOfFood;-(void) showInformation :( NSString *) foodName andShowMaterial :( NSString *) material andShowNurition :( NSString *) nutrition; @ end
 

//// Food. m // electronic menu // # import Food. h @ implementation Food @ synthesize foodName = _ foodName; @ synthesize material = _ material; @ synthesize nutrition = _ nutrition; @ synthesize kindOfFood = _ kindOfFood;-(void) showInformation :( NSString *) foodName andShowMaterial :( NSString *) material andShowNurition :( NSString *) nutrition; {_ foodName = foodName; _ material = material; _ nutrition = nutrition; NSLog (@ % @, _ foodName, _ material, _ nutrition);}-(NSString *) description {return [NSString stringWithFormat: @ food name: % @ ingredients: % @ nutrients: % @, _ foodName, _ material, _ nutrition];} @ end

#import Food.h@interface CoolFood : Food-(void)show;@end

# Import CoolFood. h @ implementation CoolFood-(void) show {NSLog (@ you selected the dish);} @ end

#import Food.h@interface HotFood : Food-(void)show;@end

# Import HotFood. h @ implementation HotFood-(void) show {NSLog (@ you selected hot dishes);} @ end

#import Food.h@interface MainFood : Food-(void)show;@end

# Import MainFood. h @ implementation MainFood-(void) show {NSLog (@ you selected hot dishes);} @ end

#import Food.h@interface Drinks : Food-(void)show;@end

# Import Drinks. h @ implementation Drinks-(void) show {NSLog (@ you selected liquor);} @ end

# Import
 
  
@ Interface BillBoard: NSObject {/** ranking */int _ rank;/** comment */NSString * _ comment;}-(id) init;-(void) showRank :( int) rank; @ end
 

# Import BillBoard. h @ implementation BillBoard-(id) init {self = [super init]; if (self! = Nil) {_ rank = 0;} return self;}-(void) showRank :( int) rank {_ rank + = rank; NSLog (@ your ranking is % d, _ rank) ;}@ end



 

Related Article

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.