Skip to content

Instantly share code, notes, and snippets.

@mcsee

mcsee/wrongMutations.py

Last active Nov 19, 2020
Embed
What would you like to do?
#Since we have a setter we can create invalid combinations
janePhoneCall = PhoneCall()
janePhoneCall.set_origin('555-5555')
janePhoneCall.set_destination('555-5555')
janePhoneCall.set_duration(60)
#We can't change destination during call. This is not enforced due to setters
#Origin and Destination cannot be the same
def set_destination(self, destinationNumber):
if destinationNumber == self._origin:
raise ValueError("Destination cannot be the same as origin")
self._destination = destinationNumber
def set_origin(self, originNumber):
if originNumber == self._destination:
raise ValueError("Destination cannot be the same as origin")
#repeated code
self._origin = originNumber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.