Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add open closed principle in python explanation
- Loading branch information
1 parent
f470e36
commit b854179
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
# Subclasses should not be able to brake superclasses | |||
|
|||
class MyDict(object): | |||
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 | |||
self.__update(iterable) | |||
|
|||
def update(self, iterable): | |||
for item in iterable: | |||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
LMMilewski
Author
Owner
|
|||
self.items_list.append(item) | |||
|
|||
# instead we do little trick that makes sure you can't override | |||
# update called by init while you can override update itself | |||
__update = update |
how about
self.items_list.extend(iterable)
?