Question
Best Practice Question - Business Logic in Value Objects?
Just wondering what people's thoughts on best practices for setting properties of Value Objects.
For instance, I have several getter/setters in one of my Value Objects with logic in the setter that uses the value to set values of other properties.
For example, I have a Value Object that has the following properties:
category (of type Category, which is another Value Object with properties "name" and "id")
categoryId (of type int)
categoryUpdated (of type Boolean)
I have a collection of Category Objects in the Model. When I set the categoryId of this class, I set the "categoryUpdated" to true, and dispatch an CairngormEvent to that find the "category" with the specified "categoryId" and set the "category" property to this item.
So what is the best practice? To simply make the "categoryId" a public variable, and create a new Event/Command to perform all this logic? Or is it ok to do it all in the Value Object setter?
Thanks.
For instance, I have several getter/setters in one of my Value Objects with logic in the setter that uses the value to set values of other properties.
For example, I have a Value Object that has the following properties:
category (of type Category, which is another Value Object with properties "name" and "id")
categoryId (of type int)
categoryUpdated (of type Boolean)
I have a collection of Category Objects in the Model. When I set the categoryId of this class, I set the "categoryUpdated" to true, and dispatch an CairngormEvent to that find the "category" with the specified "categoryId" and set the "category" property to this item.
So what is the best practice? To simply make the "categoryId" a public variable, and create a new Event/Command to perform all this logic? Or is it ok to do it all in the Value Object setter?
Thanks.
