Skip to content

Instantly share code, notes, and snippets.

@tornikegomareli
Last active June 20, 2023 08:23
Show Gist options
  • Save tornikegomareli/5ee92863f936f67d3b47c84946d13bff to your computer and use it in GitHub Desktop.
Save tornikegomareli/5ee92863f936f67d3b47c84946d13bff to your computer and use it in GitHub Desktop.
Swift OOP Task for Students
Exercise Title: Restaurant Management System
Objective: Create an object-oriented program using Swift to simulate the operations of a restaurant.
Your main entities will be Chef, Waiter, Customer, Order, Menu, and FoodItem. Your program should demonstrate a
comprehensive understanding of protocols, multiple protocols, inheritance, and polymorphism.
Instructions:
Protocols:
Create a protocol Employable that defines common attributes like name, id, salary, and functions such as work().
Create another protocol Orderable that contains attributes like orderId, customerName, totalPrice, and functions
like addToOrder(), removeFromOrder(), calculateTotal().
Create another protocol Consumable with methods like prepare(), serve().
Inheritance and Multiple Protocols:
Create classes Chef and Waiter that inherit from a parent Employee class and conform to the Employable protocol.
Ensure to override some methods in these child classes to depict polymorphism. For example, work() for a Chef
could be preparing food, while for a Waiter it could be serving food or cleaning tables.
The Employee class should have properties like workHours, uniform, workStatus, and a method like takeBreak().
Menu and FoodItem:
Create a Menu class that has attributes such as menuItems (an array of FoodItem objects). It should have methods
like addMenuItem(), removeMenuItem().
Create a FoodItem class conforming to the Consumable protocol with properties like name, ingredients, price,
and preparationTime.
Customers and Orders:
Create a Customer class with attributes like name, orderHistory, bill, and methods like orderFood(), payBill().
Create an Order class conforming to the Orderable protocol with properties like items (an array of FoodItem objects),
orderStatus, waiterName.
Bonus Task (for Extra Credit):
Implement a Restaurant class that maintains the state of all Employees, Menu, Orders, and Customers.
Implement methods like openRestaurant(), closeRestaurant(), hireEmployee(), fireEmployee(), customerEnters(),
customerLeaves(). The Restaurant class should manage the daily operations and interactions between Customers, Employees,
Menu, and Orders.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment