IIKH Class from Timothy Budd's introduction to OOP

 Timothy Budd의 An Introduction to OOP 3ed. IIIKH(Intelligent Interactive Kitchen Helper)

앞서 객체 지향 프로그래밍의 가장 큰 특징은 Separation of implementation and interface라고 하였다. 즉, 사용자는 해당 오브젝트의 기능들이 어떻게 실현되었는지 알 필요 없이 해당 오브젝트가 제공하는 기능들 만 사용할 수 있는 것이다.

그래서 책의 예제에 제공되는 6개의 클래스가 어떤 기능을 가져야 하는지 public / private 에 대해서 attribute와 method를 생성하였다.


#pragma once
class Greeter { //greeter component that starts at the very beginning of IIKH. It provides several menu for user to choose.
private:
    void show_menu(); // main display window when IIKH is started and offer several choices.

public:
    void call_RecipeDatabase(); // if user selects browse, add, edit recipe.
    void call_PlanManager(); // if user selects review or create meal plan.
};

class RecipeDatabase { // RecipeDatabase component that store recipes and manage them.
private:
    Recipe recipeList[100]; //store list of recipe components(objects) and can return, edit, add whenever needed.

public:
    void browse_recipe(); // browse database of recipes.
    void add_recipe(); // create a new recipe.
    void delete_recipe(); // delete recipe.
    void edit_recipe(); // edit recipe.
    void search_recipe(); // search specific recipe by it's name.
};

class PlanManager { // PlanManager component that show plans and allow user to select date for planning.
private:
    Date dateList[100]; // store list of Date components(objects) and can return or edit on demand.

public:
    void show_date(); // show several previous date's meal plans.
    void create_date(); // create a new plan of meals for specific date.
};

class Date {
private:
    int date; // exact date of the day (yyyymmdd)
    char* dateInfo; // information about the date.
    Meal mealList[100]; // store the meal list for the day.

public:
    void print_groceryList(); // use the mealList's value and return grocery list for the day. (combine each meal's groceryList)
    void edit_date(); // user can edit the date's info.
};

class Meal { // component of couple recipes and participants in the meal. It can store or set those values.
private:
    int peopleSize; // the number of people present at meal.
    Recipe recipes[100]; // holds the list of recipes selected at the meal.
    char* groceryList[100]; // grocery list for the selected recipes.
    void scaler(); // combine each recipe's ingredients. also, use the value of peopleSize to scales the recipe's ingredient and set thos into groceryList.

public:
    void set_peopleSize(); // sets the number of people present at meal
    void call_recipeDatabase(); // call the RecipeDatabase and allow user to select list of recipes for the meal.
    char** return_groceryList(); // return the list of whole ingredients scaled by number of peopleSize.
};

class Recipe { // Recipe component which stores ingredients need and steps to cook. it can also show and edit those values.
private:
    char* menuName; // store the name of recipe.
    char* ingredient[100]; // store the ingredients required.
    char* cookingStep[100]; // store how to cook this menu step by step.

public:
    void edit_recipe(); // can edit name, ingredient, cooking method.
    void display(); // show the cooking step and required ingredient for the recipe.
    char** return_ingredient(); // return the list of ingredient so the Meal component can set the grocery list.
};

댓글

이 블로그의 인기 게시물

Compiler 9 - Efficient Code generation

Software Engineering 10 - V&V, SOLID principle