Serialize and event model

V

VisionSet

I have a bunch of model classes that I use on client and server. When a
model object gets serialized all the observers of that model that are my
clients view need to be removed. But I have internal model observers also -
not sure that was wise? Now at the present state of the design it is proper
to remove all observers whatever, but that may not end up being the case. I
know I can track the type of observer that is being added not a problem and
remove certain types when the time comes. My real question is where do I do
the removal? At present I do it like this:

private void writeObject(ObjectOutputStream s) throws IOException {
observers.clear();
s.defaultWriteObject();
}

Can anyone see a problem with that?
At the moment I could declare my observer collection transient, and lazily
reinstantiate, but like I said thats a bit presumptious.
Any other tips in this regard?

TIA
 
G

G Winstanley

I have a bunch of model classes that I use on client and server. When a
model object gets serialized all the observers of that model that are my
clients view need to be removed. But I have internal model observers also -
not sure that was wise? Now at the present state of the design it is proper
to remove all observers whatever, but that may not end up being the case. I
know I can track the type of observer that is being added not a problem and
remove certain types when the time comes. My real question is where do I do
the removal? At present I do it like this:

private void writeObject(ObjectOutputStream s) throws IOException {
observers.clear();
s.defaultWriteObject();
}

Can anyone see a problem with that?
At the moment I could declare my observer collection transient, and lazily
reinstantiate, but like I said thats a bit presumptious.
Any other tips in this regard?

TIA

I don't see why you have to clear the observers. The normal procedure
would be to declare the collection of observers transient, then
re-register them if/when necessary on deserialization.

Stan
 
V

VisionSet

I don't see why you have to clear the observers. The normal procedure
would be to declare the collection of observers transient, then
re-register them if/when necessary on deserialization.

Yeah that's what I've done, and lazily reinstantiate the collection afer
deserialisation.

Thanks,
 
G

G Winstanley

Yeah that's what I've done, and lazily reinstantiate the collection afer
deserialisation.

Thanks,

Oops, I missed that last past of your posting. Shouldn't read things in
a hurry. That should be all you need to do, unless you have some unusual
requirements for some reason.

Stan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top