|
Boost Users : |
Subject: Re: [Boost-users] Trying to serialize observer pattern - both subject and observers with pionters
From: Mikael Carlsson (mika_at_[hidden])
Date: 2009-09-08 04:50:05
Hi,
> > 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.
I have included a small piece of code. It illustrates how I have interpreted
the documentation. As you can see I use BOOST_CLASS_EXPORT (from what I read
above, this is not needed). If I exclude the BOOST_CLASS_EXPORT I get
"unregistered class" exception. If I include it, it appears to works but I
get seg. fault during main exit (most likely a different problem related to
my environment). I guess that I am using some parts of the library
incorrect.
> > 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
Understood, but I do not have a circular dependency between derived/base
class, but with concrete observable(subject) and concrete observers.
>
>
> > 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.
I guess you are right, I think I understand.
> The library can handle circular pointer references with no problem.
Understood (and agreed)
/ Mikael Carlsson
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net