Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active May 31, 2022 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsee/b5eebe620b66c510bafe04a7a4f8ef82 to your computer and use it in GitHub Desktop.
Save mcsee/b5eebe620b66c510bafe04a7a4f8ef82 to your computer and use it in GitHub Desktop.
class Date:
def __init__(self, day, month, year):
if month > 12:
raise Exception("Month should not exceed 12")
#
# etc ...
self._day = day
self._month = month
self._year = year
startDate = Date(3, 11, 2020)
# OK
startDate = Date(31, 11, 2020)
# fails
startDate.setMonth(13)
# fails since invariant makes object immutable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment