gang-of-4-patterns AT lists.siebelschool.illinois.edu
Subject: Design Patterns discussion
List archive
- From: "Chris Finlayson" <cfinlayson AT vls-inc.com>
- To: <gang-of-4-patterns AT cs.uiuc.edu>
- Subject: [gang-of-4-patterns] design patterns & serialization
- Date: Tue, 2 Dec 2003 20:53:05 -0700
- Importance: Normal
- List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns/>
- List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>
Hi all:
I have a very basic question - I may be missing something here.
In following design patterns, one has interfaces and abstract classes all
over the place - how does one "properly" go about serializing/deserializing
objects whose exact class is unknown?
Take a simple example where one is serializing out a concrete strategy
selected at run-time, and then wants to
read it back in at a later point:
----------begin some program--------------------
ISortStrategy oStrategy = SortFactory::Create("QuickSort");
//....
//doing some with oStrategy
//.....
oStrategy.serialize(somestream) //The concrete QuickSort strategy is
serialized out
//now I want to read it back in..what do I do hear?
//I could do something like:
oStrategy = SortFactory::Deserialize(somestream);
--------------end some program---------------
I would have each of my concrete sort strategies write out some sort of
identifier prior to writing the data, so the resultant serialized data would
look something like:
QuickSort
data....
Then, SortFactory's "Deserialize" method would look something like:
Deserialize(somestream)
{
string objecttype = ..... //read in object type from stream
ISortStrategy oStrategy = SortFactory::Create(objecttype)
oStrategy.deserialize(somestream);
}
Is there a better way to do this?
Thanks! --Chris.
- [gang-of-4-patterns] design patterns & serialization, Chris Finlayson, 12/02/2003
- <Possible follow-up(s)>
- RE: [gang-of-4-patterns] design patterns & serialization, Ray Ye, 12/03/2003
- RE: [gang-of-4-patterns] design patterns & serialization, Chris Finlayson, 12/03/2003
Archive powered by MHonArc 2.6.16.