Given an application that involves, say, Companies, I might have a Company class. I will have a data access layer that populates a List <Company>. However, there will be times (such as displaying a search result) where I only need to display the Company name, telephone and postcode properties, and it seems to me that populating the entire Company object with all its properties seems wasteful.
What would be the right way to go about this in terms of a DDD design? Would I create View specific classes, such as a CompanySearchResult object which only exposes the properties I’m interested in displaying?
That sounds like a reasonable approach to me.
Later on, if the customer comes to you asking for your
SearchResultto display something unrelated to theCompanymodel – something crazy like the number of nearby ice cream shops you’ll have a much easier time appending this to yourCompanySearchResultthan your domain object.