Trying to serialize observer pattern - both subject and observers with pionters
Dear list, I am using the observer pattern in a design and would like to make both subject and observers serializable. The subject hold a base class pointer to the observes and the observers holds a base class pointer to the subject. If I have understood the library correct I must register the class for base class pointers in order to serialize the class pointer. This means that I must include the concrete subject in the concrete observers and vice versa. The means that I will run into circular dependencies. I guess that I am missing something here, the observer pattern must be frequently used and be serialized. Have anyone used the observer pattern and managed to serialize both observers and subject with pointers included. / Mikael
Mikael Carlsson wrote:
Dear list,
I am using the observer pattern in a design and would like to make both subject and observers serializable. The subject hold a base class pointer to the observes and the observers holds a base class pointer to the subject.
If I have understood the library correct I must register the class for base class pointers in order to serialize the class pointer.
Nope - you just have to indicate the base class for each class that has one.
This means that I must include the concrete subject in the concrete observers and vice versa. The means that I will run into circular dependencies.
Nope C++ doesn't permit a circular derived/base class structure
I guess that I am missing something here, the observer pattern must be frequently used and be serialized.
You're confusing the class structure which cannot be circular with a seqence of pointers which can be circular. The library can handle circular pointer references with no problem. Robert Ramey
participants (2)
-
Mikael Carlsson
-
Robert Ramey