Value vs Entity objects (Domain Driven Design)

Reduced to the essential distinction, identity matters for entities, but does not matter for value objects. For example, someone’s Name is a value object. A Customer entity might be composed of a customer Name (value object), List<Order> OrderHistory (List of entities), and perhaps a default Address (typically a value object). The Customer Entity would have … Read more

Persist Data by Programming Against Interface

Your repository should accept BankAccount – not IBankAccount because Linq-to-sql doesn’t know what is IBankAccount and compiler doesn’t allow you to store it without casting it first to BankAccount (that can obviously fail at runtime if IBankAccount instance is not a BankAccount). Once you have BankAccount you simply call: Context.BankAccounts.Add(account); Context.SubmitChanges();

Is it ok for entities to access repositories?

it’s not a horrible violation of DDD it’s a horrible violation of… well… it’s just plain horrible (i say this tongue in cheek) :). First off, your entity becomes dependent on having a repository… that’s not ideal. Ideally you’d want to have your repository create the Person and then assign it everything it needs to … Read more

Should services always return DTOs, or can they also return domain models?

it doesn’t feel right when domain model leaves business layer (service layer) Makes you feel like you are pulling the guts out right? According to Martin Fowler: the Service Layer defines the application’s boundery, it encapsulates the domain. In other words it protects the domain. Sometimes service needs to return data object that wasn’t defined … Read more

What are the benefits of Persistence Ignorance?

Let me explain this with an example. Lets assume your are implementing an application using a classical SQL approach. You open recordsets, change data and commit it. Pseudo code: trx = connection.CreateTransaction(); query = connection.CreateQuery(“Select * from Employee where id = empid”); resultset = query.Run(); resultset.SetValue(“Address_Street”, “Bahnhofstrasse”); resultset.SetValue(“Address_City”, “Zürich”); trx.Commit(); With NHibernate it would look … Read more

What is the difference between DAO and Repository patterns?

DAO is an abstraction of data persistence. Repository is an abstraction of a collection of objects. DAO would be considered closer to the database, often table-centric. Repository would be considered closer to the Domain, dealing only in Aggregate Roots. Repository could be implemented using DAO‘s, but you wouldn’t do the opposite. Also, a Repository is … Read more

Domain Driven Design: Domain Service, Application Service [closed]

Services come in 3 flavours: Domain Services, Application Services, and Infrastructure Services. Domain Services : Encapsulates business logic that doesn’t naturally fit within a domain object, and are NOT typical CRUD operations – those would belong to a Repository. Application Services : Used by external consumers to talk to your system (think Web Services). If … Read more

Who should handle the conditions in complex queries, the data mapper or the service layer?

The data mapper pattern only tells you, what it is supposed to do, not how it should be implemented. Therefore all the answers in this topic should be treated as subjective, because they reflect each authors personal preferences. I usually try to keep mapper’s interface as simple as possible: fetch(), retrieves data in the domain … Read more