Please sign in to comment.
add open closed principle in python explanation
- Loading branch information...
Showing with 33 additions and 2 deletions.
|@@ -0,0 +1,17 @@|
|+# Subclasses should not be able to brake superclasses|
|+ def __init__(self, iterable):|
|+ self.item_list = |
|+ # we don't want to call update here, because if subclass|
|+ # overrides update it can break __init__ which is not expected|
|+ # behaviour by the subclass|
|+ def update(self, iterable):|
|+ for item in iterable:|
|+ # instead we do little trick that makes sure you can't override|
|+ # update called by init while you can override update itself|
|+ __update = update|