I am trying to separate behaviour from data completely in my classes and came up with this simple solution:
class ClassAData
{
public int Property1;
public string Property2;
public bool Property3;
}
class ClassA : SomeInterface
{
public ClassAData Data;
//behaviour
public int CalculateSomething(int value)
{
...
return result;
}
public string SomeOtherMethod(){...}
}
(proper encapsulation would of course be applied...)
I was wondering if this is known by something or used in a common pattern? Also what are the shortcomings if there are any?
Edit: Perhaps I should have been clearer about where I intend to use this. I do not advocate using this for every class in every situation. I plan to use this in a service-oriented application where ClassA is the actual domain object and ClassAData would be a DTO that is transferred between the service and presentation layers. This approach avoids a fair bit of code duplication especially if there are many classes with lots of properties.