class UserInfo(object):
pass
class Department(object):
pass
class StarkConfig(object):
def __init__(self, num):
self.num = num
def get_vals(self):
v = [11, 22, 33]
extra = self.extra_vals()
if extra: # 如果extra为真,(None为假) 条件成立
v.extend(extra)
return v
def extra_vals(self):
pass
def run(self):
return self.get_vals()
class RoleConfig(StarkConfig):
def extra_vals(self):
return [99, 88]
class AdminSite(object):
def __init__(self):
self._registry = {}
def register(self, k, v):
self._registry[k] = v(k)
site = AdminSite()
site.register(UserInfo, StarkConfig)
site.register(Department, RoleConfig)
for k, row in site._registry.items():
print(row.run())