Dynamic-Polymorphing Class Object Challenge
Put on your thinking caps.....
I'm just curious in how many different ways the following concept could be
implemented. I have two in my head, thinking that opne might be better than the
other. I have done my best to avoid using coded examples in an effort to not
give any preconceptions.
I'm not necessarily looking for actual code, but rather pseudo code &
theoreticals (but I'm not going to deny actual code if you have it.)
Concept:
A sort of "Ad-Hoc" class. The class to be implemented as an ActiveX DLL that
would exhibit the following characteristics:
1) Dynamic Properties. In one instance (Obj1), I may need a property called
"Prop1", but in another (Obj2), it might be "Property1". Properties may need to
be added on the fly.
2) The class may or may not be "hard". "HUH?!" you say. Meaning that once the
property structure is set, it cannot be changed or added to. Let's say that Obj1
from the previous example is "hardened", but Obj2 isn't. If I assign a value to
the property "Property1" of Obj1, an error ocurrs. But, if I assign a value to
the property "Prop1" of Obj2, no error ocurrs, and I can retrieve the value
later. NO CHANGES to the object's structure should be allowed. For flexability,
could be an On/Off switch. Or, it can be set once and that's it.
3) Persistance. It must have a way to save it's state. May or may not be to
the hard drive. This includes both data and structure.
4) Serialization. Most good objects should do this.
5) Copy or clone method.
6) For a lack of a better term, Templating. Same as persistance, but structure
only. After the object is created, the structure is loaded and then optionaly
hardened.
7) Merge. Able to take the structure of one object and merge it (or the
properties) into another. For example, if I take Obj2 and merge it into Obj1
(assuming Obj1 isn't hardened), Obj1 would then have both "Prop1" and
"Property1" properties.
8) Data Overlay. As an addon to #7, optionaly include data as well as the
structure. Be able to indicate whose data over writes whose in the event that
common properties are found.
9) Simple. Above all else, it should be simple to use. Allow for the greatest amount of flexability in the least number of steps.
There's no prize. And like I said, no actual code is expected, I'm only looking for theoretical ideas. Although, if you want to spend the time trying to code something & would like ot share it, then by all means, be my guest. As for me, I already have worked out some ideas in my mind (I don't plan to post them for a little while to prevent preconceptions, but eventually, I will.)
1 Attachment(s)
Ah, ha! Took me a while... but here it is at last!
Here's my solution -- this is the one that's been running around in my brain all afternoon.
Took me awhile, but I got it.
One caveat: It uses MSXML (v2.0) so, to use it, you'll need to get MSXML from Microsoft.
There are some great ideas in here....
He's got one up on us Edneeis, I didn't think about removing properties. I also like the idea of a Release method that essentially clears out the object.
One thing of note was the (De)Serialization. When deserializing, you write out each property in a name/value pair, but in the serializing, you only read in the first one. But then again, I had only asked for theoreticals.