Created
August 16, 2016 13:47
-
-
Save dboyliao/684706d4d570707316beaad6b4c3e45f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
import sys | |
class A(object): | |
""" | |
Base Class | |
""" | |
def __init__(self): | |
self._dict = {} | |
self._count = 0 | |
print("self._dict = " + str(self._dict)) | |
print("self._count = " + str(self._count)) | |
self.__add_by_a() | |
def __add_by_a(self): | |
if len(self._dict) == 0: | |
print("add pair by A") | |
self._dict["key_a"] = "value_a" | |
else: | |
sys.exit("error: _dict not empty") | |
if self._count == 0: | |
print("count plus 1 by A") | |
self._count += 1 | |
else: | |
sys.exit("error: _count not empty") | |
class B(A): | |
""" | |
Sub Class B | |
""" | |
def __init__(self): | |
super(B, self).__init__() | |
self.__add_by_b() | |
print(self._dict) | |
print(self._count) | |
def __add_by_b(self): | |
print("add pair by B") | |
self._dict["key_b"] = "value_b" | |
print("count plus 1 by B") | |
self._count += 1 | |
class C(A): | |
""" | |
Sub Class C | |
""" | |
def __init__(self): | |
super(C, self).__init__() | |
self.__add_by_c() | |
print(self._dict) | |
def __initializing(self): | |
self.__add_by_c() | |
def __add_by_c(self): | |
print("add pair by C") | |
self._dict["key_c"] = "value_c" | |
print("count plus 1 by C") | |
self._count += 1 | |
def main(): | |
obj_B = B() | |
print("-----") | |
obj_C = C() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment