Group Testing Pure Domain-Managed Classes

I strive to create a system based on a clean domain design. As far as I know, this means that my domain objects should have behavior, but not form. That is, they should not have any getters or other accessories.

At the same time, I am trying to monitor TDD processes and have run into a stumbling block with the test I am trying to write.

[Test] public class new_purchase_order_should_have_purchase_ordernumber_of_1 { PurchaseOrder po = PurchaseOrder.CreatePurchaseOrder() Assert.AreEqual(1,po.PurchaseOrderNumber); } public class PurchaseOrder { private int _purchaseOrderNumber; static CreatePurchaseOrder() { _purchaseOrderNumber = SomeWayOfGettingAPONumber() //other initialisation } public int PurchaseOrderNumber {get { return _purchaseOrderNumber;} } 

If getters are not allowed, how can I verify that the CreatePurchaseOrder () methods work correctly and sets the value to 1.

This is a big conceptual obstacle for me in trying to implement this design, so any advice would be really helpful.

thanks

+4
source share
2 answers

Why can't a domain object have properties? The pure behavior you are talking about is just static methods; they have nothing to do with Domain objects.

wikipedia tells us:

a business object usually does nothing on its own, but contains a set of instance variables or properties, also called attributes, and associations with other business objects, weaving a map of objects representing business relationships.

A domain model where business objects have no behavior is called an anemic domain model.

So, it turns out that the domain object should have properties and (in most cases) behavior.

Martin Fowler says:

Domain Model - A domain object model that includes both behavior and data.

+6
source

One way to achieve this goal is to follow the CQRS idea.

CQRS divides requests from behavior at the architectural level (hence the name) and uses the published domain model events to expose the state.

But it is quite difficult to understand and implement correctly. Especially if you do not have experience with design ideas based on the domain as a whole.

Therefore - do not hesitate to disclose the state, just make sure that it can only be changed from the object itself.

+1
source

Source: https://habr.com/ru/post/1339567/


All Articles