0

I see Composite Oriented Programming and DCI as interesting techniques to use within a rest framework, but have run into an issue. Is it possible to serialize a mixin object and get all it's properties? For example:

public class IHasOwner 
{ 
  string owner(); 
} 

public class HasEngine 
{ 
  string engine(); 
}

Let's say we make a CarComposite object with the two classes above as mixins. Could I deserialize this CarComposite class to get the following xml?:

<CarComposite> 
   <owner></owner> 
   <engine></engine> 
</CarComposite> 

I'm curious to how this is handled in general, but with close attention to .NET, since you canot deserialize Interfaces.

Bless Yahu
  • 1,331
  • 1
  • 12
  • 25
  • I guess you could always roll a serializer by hand on top System.Xml classes, rigtht? Could you elaborate on why that might not solve your problem, and on how you construct the composite from the mixins in C#? – Christian Horsdal Nov 27 '11 at 19:52
  • I could construct the composite using dynamic proxy or re-mix. I want be able to compose my domain objects from various objects, instead of using inheritance. Similar to what you can do with Qi4J. I guess it would need a custom serializer. – Bless Yahu Nov 28 '11 at 12:36
  • I'm seeing if mixing can be used with Rest, like OpenRasta. Maybe the answer is to map composed domain objects to resources created with inheritance. It's the resource that gets passed back, not the domain. That way resources should Serializer fine. – Bless Yahu Nov 28 '11 at 12:41
  • I find that a view- or resource-model is often called for in RESTful services. I.e. a set of dumb data types tailored for the way you want to expose the resource. These do not need to match domain objects. You do need to be able map between the two though. The dumb resource-model is "easy" to serialize. – Christian Horsdal Nov 28 '11 at 12:45
  • We are thinking along the same lines. Put this as an answer so I can credit you. – Bless Yahu Dec 16 '11 at 13:50

1 Answers1

1

I find that a view- or resource-model is often called for in RESTful services. I.e. a set of dumb data types tailored for the way you want to expose the resource. These do not need to match domain objects. You do need to be able map between the two though. The dumb resource-model is "easy" to serialize.

For the mapping between domain and service model objects AutoMapper can be quite useful.

Christian Horsdal
  • 4,914
  • 23
  • 24