This repo is a small, progressive demo of Python classes, inheritance, and simple business rules using a food-themed domain. It includes base classes, subclasses, and behavior rules to illustrate how state and logic can live on objects.
food.py- Base class:
Food - Subclasses:
Fruit,Meat,Beverage
- Base class:
meal.py- Composition:
Meal
- Composition:
person.py- Base class:
Person - Subclass:
Vegetarian
- Base class:
- Inheritance and method overriding (
Fruit.eat,Meat.eat,Beverage.drink) - Composition (
Mealcontains multipleFooditems) - State and validation inside methods (edibility, allergies, hand-washing)
- Polymorphism (different
Foodtypes can be handled uniformly) - Simple domain rules (vegetarian restriction, diabetic fruit limit, alcohol age check)
- People must wash hands before eating/drinking.
Fruitmust be washed and ripe before it can be eaten.Meatmust be cooked before it can be eaten.Vegetariancannot eatMeat.- Diabetics can only eat one fruit.
- Alcoholic beverages require age 21+.
- During a
Meal, people only become full at the end of the meal.
Run any example with:
python example01.pyExample progression:
example01.py— Minimal: 1Person, 1Foodexample02.py—Meatcooking requirementexample03.py—Fruitwashing/ripening +Meatexample04.py— Allergies,Vegetarian, and diabetic fruit limitexample05.py—Beveragewith adult vs childexample06.py— Allergy restriction exampleexample07.py—Mealwith beverages and age rulesexample.py— Full demo combining multiple features
food.pymeal.pyperson.pyexample.pyexample01.pyexample02.pyexample03.pyexample04.pyexample05.pyexample06.pyexample07.py