vendredi 23 octobre 2020

How to predefine the class in python? [duplicate]

I try to implement the Observer pattern with requests for subscribing and unsubscribing the updates and faced a problem. I cannot call the object of the class that was not still defined. It is a problem because I cannot just swap classes "observer" and "observable" because each of them calls another. I have something like that:

from abc import ABC, abstractmethod

class OBSERVER(ABC):
    def subscribe(self, observable: OBSERVABLE):
        observable.register(self)

class OBSERVABLE(ABC):
    def register(self, observer: OBSERVER):
        self.observers.append(observer)

How could I implement this? Is it possible?

Aucun commentaire:

Enregistrer un commentaire