Quantcast
Viewing all articles
Browse latest Browse all 6

Making objects behave across a client-server relationship. Part 1 - The scenario.

Ok, so here's the scenario. I have a set of objects, which all inherit from Element (shown below). I need these objects to behave properly when transferred across a web service, and more importantly, when they return. One assumption I want to be able to make, is that any Element contained in the Children property, should have its Parent property set to the containing object, so it's a node-like structure. Furthermore, I need my non-default constructor logic to apply, to de-serialized objects, as if they were initialized with my parameterized constructor.

public abstract class Element {
public Element() {
this.Children = new List<Element>();
}
public int ID { get; protected set; }
public string Name { get; protected set; }
public virtual Element Parent { get; internal set; }
public virtual List<Element> Children { get; private set; }
public string Instructions { get; set; }
}

The problems:

How to make sure that any objects added to the Children property, gets a correct reference to the parent object (this)?

How to make sure that my object can be serialized in an orderly fashion?

How to enforce that initialization is done properly once the object has been de-serialized?

 


Viewing all articles
Browse latest Browse all 6

Trending Articles