本文整理汇总了Python中observable.Observable.register_observer方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.register_observer方法的具体用法?Python Observable.register_observer怎么用?Python Observable.register_observer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类observable.Observable
的用法示例。
在下文中一共展示了Observable.register_observer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QuackCounter
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import register_observer [as 别名]
class QuackCounter(Quackable):
number_of_quacks = 0
def __init__(self, quackable):
self._quackable = quackable
self._observable = Observable(self)
def __repr__(self):
return repr(self._quackable)
def quack(self):
self._quackable.quack()
QuackCounter.number_of_quacks += 1
self.notify_observers()
def register_observer(self, observer):
self._observable.register_observer(observer)
def notify_observers(self):
self._observable.notify_observers()
@classmethod
def get_quacks(cls):
return cls.number_of_quacks
示例2: RubberDuck
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import register_observer [as 别名]
class RubberDuck(Quackable):
def __init__(self):
self._observable = Observable(self)
def __repr__(self):
return "RubberDuck"
def quack(self):
print "Squeak"
self.notify_observers()
def register_observer(self, observer):
self._observable.register_observer(observer)
def notify_observers(self):
self._observable.notify_observers()
示例3: DuckCall
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import register_observer [as 别名]
class DuckCall(Quackable):
def __init__(self):
self._observable = Observable(self)
def __repr__(self):
return "DuckCall"
def quack(self):
print "Kwak"
self.notify_observers()
def register_observer(self, observer):
self._observable.register_observer(observer)
def notify_observers(self):
self._observable.notify_observers()
示例4: GooseAdapter
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import register_observer [as 别名]
class GooseAdapter(Quackable):
def __init__(self, goose):
self._goose = goose
self._observable = Observable(self)
def __repr__(self):
return repr(self._goose)
def quack(self):
self._goose.honk()
self.notify_observers()
def register_observer(self, observer):
self._observable.register_observer(observer)
def notify_observers(self):
self._observable.notify_observers()