Design and implementation of electronic menus for iOS development (inheritance, encapsulation, polymorphism)

Source: Internet
Author: User

  main.m//  E-menu//#import <Foundation/Foundation.h> #import "Food.h" #import "CoolFood.h" #import " HotFood.h "#import" MainFood.h "#import" Drinks.h "#import" BillBoard.h "int main (int argc, const char * argv[]) {Food            * food = [[Food alloc]init];    [Food showinformation:@ "andshowmaterial:@" pork onion ginger garlic "andshownurition:@" calcium iron Zinc new vitamin "];    NSLog (@ "%@", food);    @autoreleasepool {                //Insert code        here ... NSLog (@ "Hello, world!");            }    return 0;}
  menu.h//  E-menu//#import <Foundation/Foundation.h> #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 number of order meals * *    int _recordoffood;        /** is used to record order status */    BOOL _statusoffood;        /** used to record food prices */    int _priceoffood;} -(void) Showinformation: (food *) food; @end
  menu.m//  E-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///*    can be implemented using inherited    electronic menus    1. Food class */#import <foundation/foundation.h>@ Interface food:nsobject{    /** used to record the name of the dish * *    * NSString * _foodname;        /** Composition Material    */NSString * _material;        /** Nutrition Information    * * NSString * _nutrition;        /** used to record food types * *    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//  E-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 chose a cold dish");} @end

#import "Food.h" @interface hotfood:food-(void) show; @end

#import "HotFood.h" @implementation hotfood-(void) show{    NSLog (@ "You chose a hot dish");} @end

#import "Food.h" @interface mainfood:food-(void) show; @end

#import "MainFood.h" @implementation mainfood-(void) show{    NSLog (@ "You chose a hot dish");} @end

#import "Food.h" @interface drinks:food-(void) show; @end

#import "Drinks.h" @implementation drinks-(void) show  {    NSLog (@ "Your choice is Wine");} @end

#import <Foundation/Foundation.h> @interface billboard:nsobject{    /** ranking */    int _rank;        /** comments */    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 rank is%d", _rank);} @end



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

Design and implementation of electronic menus for iOS development (inheritance, encapsulation, polymorphism)

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.