How bad is it? I have read countless articles and never created abstract DataContracts with behavior before, but it seems that doing so will solve an issue I am having that will prevent me from creating factories everywhere to determine a subclass implementation. My question is, will I be punished if I decide to add behavior to my data contracts? Of course they can't be consumed and are there to perform certain operations specific to that subclass type before invoking repository calls and data is persisted. I can create "Manager" classes for each subclass but that puts me back at factories and I am trying a more polymorphic approach. Thanks in advance.
Data contracts involve large quantities of technical metadata. To document your data pipelines and data products, you must have a clear description of your data sources, all transformations your data has undergone, and how you ultimately deliver the data.
Data contracts are a relatively new yet important addition to data mesh architecture, providing transparency for data usage and dependencies. Focus on technical stability and standardization as you first begin to use data contracts, then use a lessons-learned process as you iterate.
During the weekdays, students spend most of their time inside classrooms anyway. On that note, a behavior contract is planned. This marks as a written agreement form between the child, the parent, the teacher, and the school.
A data contract precisely defines, for each parameter or return type, what data is serialized (turned into XML) to be exchanged. Windows Communication Foundation (WCF) uses a serialization engine called the Data Contract Serializer by default to serialize and deserialize data (convert it to and from XML).
You can add all the behavior you want to your data contracts. You should clearly document the fact that the behavior won't be visible to clients, or someone will be disappointed later on. Also document the fact that care must be taken to not add any implementation-dependent data to the data contract, since it's not anything you want to pass to the clients.
All in all, I think you'd be better off to let data contracts be data contracts, and to leave the behavior out of them.
Why can't you create your data contract (MyDataContract) in a classic fashion, just data fields, nothing else, and then derive your behavior class from it?
public class BehaviorialClass : MyDataContract
{
.....
}
That way, you have a nice, clean separation of concerns, your data contract isn't "polluted" by behavior it can't really deal with anyway.....
Marc
A good compromise to putting behavior directly in your DataContracts would be define behaviors as extension methods in either the same assembly as your Contracts or a different assembly entirely. Optionally, extension methods can be placed in a separate namespace from the contracts to further insulate the separation of data and behavior.
That way your Contracts are kept clean but at the same time, .NET consumers of your contracts would have an easy way to import additional functionality relating to those DataContracts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With