Answer by M Juckes for Simulating an OOP Coffee Machine
You might gain more OOP points by using more objects. Start by defining an exception:class NotAvailable(Exception): passWhen something runs out, you can raise the exception and have the program return...
View ArticleAnswer by Laurent LAPORTE for Simulating an OOP Coffee Machine
class/instance variablesIn your code, you use class variables instead of instance variables.You have to know that class variables are shared in all instance, for example:class CoffeeMachine: water =...
View ArticleAnswer by md2perpe for Simulating an OOP Coffee Machine
Instead of def start(self): self.running = True self.action = input("Write action (buy, fill, take, remaining, exit):\n") print() #possible choices to perform in the coffee machine if self.action ==...
View ArticleAnswer by Samwise for Simulating an OOP Coffee Machine
First some basic observations:Your running variable is shared across all CoffeeMachine objects -- as soon as you create one CoffeeMachine, it starts itself, and then any subsequent CoffeeMachine you...
View ArticleAnswer by Peilonrayz for Simulating an OOP Coffee Machine
You should split business logic and user interface.Whilst it's common to get coffee machines that are hella advanced and can talk to humans.When programming you should build in layers.I always build...
View ArticleAnswer by camp0 for Simulating an OOP Coffee Machine
When you have multiple if statements, like your code does, it can be an indication that you can use a visitor pattern to your code. I will use a dict in my example.Your code:def start(self):...
View ArticleSimulating an OOP Coffee Machine
Today I learnt the basics of OOP. I have tried to apply them to this coffee machine project. However I'm still a beginner, and so I feel my code can be improved. Are there any tips, trick or other...
View Article
More Pages to Explore .....