Last active
May 31, 2022 01:24
-
-
Save mcsee/b5eebe620b66c510bafe04a7a4f8ef82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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