cosapp.patterns.observer

Classes

Observer([subject])

Generic interface for observers

Subject([obs_type])

Prototype of subject for Observer objects.

class cosapp.patterns.observer.Observer(subject=None)[source]

Bases: ABC

Generic interface for observers

observe(subject) None[source]

Sign in as observer of subject

observes(subject=None) bool[source]

Bool: does observer observe subject? If subject is None, returns True if observer observes anyone, False otherwise.

quit() None[source]

Quit observing whoever observer is currently observing

class cosapp.patterns.observer.Subject(obs_type=<class 'cosapp.patterns.observer.Observer'>)[source]

Bases: object

Prototype of subject for Observer objects. The philosophy is that observers are responsible for signing in or out. Therefore, the subject should not unilaterally add or remove observers, except when it is cleared.

add(observer)[source]

Add an observer to the list of observers. Invoked by outside observers when they sign in; should not be called by self directly.

clear() None[source]

Force all observers to quit

property n_observers: int

number of observers of current subject

Type:

int

notify(*args, **kwargs) None[source]

Notify observers that they must update

classmethod observer_type() type[source]

Returns the type of observers allowed to observe Subject

remove(observer) None[source]