Skip to Content.
Sympa Menu

gang-of-4-patterns - RE: [gang-of-4-patterns] design patterns & serialization

gang-of-4-patterns AT lists.cs.illinois.edu

Subject: Design Patterns discussion

List archive

RE: [gang-of-4-patterns] design patterns & serialization


Chronological Thread 
  • From: "Chris Finlayson" <cfinlayson AT vls-inc.com>
  • To: "'Ray Ye'" <rayye AT Catena.com>, <gang-of-4-patterns AT cs.uiuc.edu>
  • Subject: RE: [gang-of-4-patterns] design patterns & serialization
  • Date: Wed, 3 Dec 2003 14:52:08 -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:

Ray, yes, you are correct in that being my intent - my proposed solution
would put the class name preceding the object as the identifier for what
type of object it is . . . . so actually I wouldn't need to know it
beforehand. The analogy you provide to the encryption one is a good one -
I'm not sure how this handshake works, but it may complement the information
gleaned in the links sent by Dirk and Andy.

These links were quite helpful and have at this point answered all the
questions I have (when I actually get into implementing it, I'm sure I'll
get confused somewhere). I really liked the paper describing the Product
Trader pattern.

--Chris.

> -----Original Message-----
> From:
> gang-of-4-patterns-admin AT cs.uiuc.edu
> [mailto:gang-of-4-patterns-admin AT cs.uiuc.edu]On
> Behalf Of Ray Ye
> Sent: Wednesday, December 03, 2003 8:08 AM
> To:
> 'cfinlayson AT vls-inc.com';
>
> gang-of-4-patterns AT cs.uiuc.edu
> Subject: RE: [gang-of-4-patterns] design patterns & serialization
>
>
> Hi Chris,
>
> I am not sure if I understand your question completely, but
> with what I
> understand, you put "serializing" responsibility into the
> "strategy", and
> later on, you use "strategy factory" to do the
> "deserializing". I see a
> problem here, without know which serializing strategy, how
> can you even read
> "type" in from the stream? I believe in order to know the
> "type" from the
> stream, you have to read the stream in, and deserialize it,
> and then you
> would know, but if you know how to deserialize the stream in the first
> place, you would not need "type" information.
>
> This is similar to encryption/decryption process, in
> "symmetric encryption",
> encryption part uses some kind of algorithm and secret key to do the
> encryption, and then decryption part has to use the same
> algorithm and key
> to the decryption, so how does the decryption part know which
> algorithm and
> key to use?
>
> There are two ways, one is that they both know at the beginning what
> algorithm and key they are going to use to do the
> encryption/decryption. The
> second, if the algorithm and key are dynamically selected,
> then they have to
> negotiate (handshake) with each other to settle the algorithm
> and key they
> both agree on, and then they proceed to the next step,
> encryption/decryption. In your serializing/deserializing
> case, you probably
> have to do the same thing.
>
> Hope this helps.
>
> Cheers,
>
> Ray
>
> -----Original Message-----
> From: Chris Finlayson
> [mailto:cfinlayson AT vls-inc.com]
> Sent: Tuesday, December 02, 2003 10:53 PM
> To:
> gang-of-4-patterns AT cs.uiuc.edu
> Subject: [gang-of-4-patterns] design patterns & serialization
>
>
> 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 mailing list
> gang-of-4-patterns AT cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/gang-of-4-patterns
>
> _______________________________________________
> gang-of-4-patterns mailing list
> gang-of-4-patterns AT cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/gang-of-4-patterns
>
>






Archive powered by MHonArc 2.6.16.

Top of Page