0

I have domain object like this:

class Customer
{
    string FirstName {get;set;}
    string LastName {get;set;}
    DateTime DateOfBirth {get;set;}
}

Product team told me: We have to get customer by ID. Customer has information like FirstName, LastName, DateOfBirth, Age and blank fields. Age and blank fields can be calculated. There is no application, just API. Who consumes this API doesn't matter.

Q: If I follow Domain Driven Design how domain class Customer looks? Where I put fields like Age and list of blank fields (for every Customer)? How business logic class looks like?

user2457382
  • 329
  • 4
  • 14
  • " We need to know how old our customer is and what fields are empty." To me, those look like queries. Unless the data is used to maintain the invariant of this entity, I wouldn't expect them to be part of the entity. – VoiceOfUnreason Mar 11 '16 at 21:02
  • From product team point it looks like queries. Let say - requirement is to have on each customer this data. Regarding this, I made private methods. Every customer has this data. – user2457382 Mar 11 '16 at 21:10
  • 1
    Doesn't look like a domain object to me, rather a DTO or database model class. – Alexey Zimarev Mar 12 '16 at 15:16

1 Answers1

0

I think you have an anaemic model going here. The age should be implemented completely in the Customer class. So that to access the value, you do, customer.age. The blankfields might be a concept that needs it's own entity/domain, because a "Customer" cannot have a "blankfield"; the language doesn't fit/make sense. If you need the "blank fields" to exist as part of a customer object though, consider using a value object inside the customer object as well.

You don't need the service doing all that you have it doing. The only reason the service might be involved in this is if there's no way you can have your entity doing the work because of an external dependency or possibly complexity.

So, your service constructs your database from your persisted data and that's the end of it's involvement. In fact, you should probably be using a repository for re-constituting your object (instead of a service).

Louis
  • 1,194
  • 1
  • 10
  • 15