The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

dmag (2) [Avatar] Offline
#1
Hi All,

In my previous work place we worked on web application which uses "Exposed Domain Model" pattern and our customer wanted interfaces to be introduced to the Domain objects.
For example, User Domain object is introduced with a IUser interface which has methods corresponding to getters and setters.
And all the DAOs and Services, return IUser interface references to the presentation tier in lieu of User references.
For example in UserService,

public List<IUser> retriveAllUsers() {
.............
.............
}

is used instead of

public List<User> retriveAllUsers() {
.............
.............
}

From my point of view this is clearly waste of time and we won't actually expose domain objects to the presentation tier also I have a doubt that this breaks the original "Exposed Domain Model" pattern.
I would like to know your opinion regarding this.

Best Regards,
dmag
simbo1905 (30) [Avatar] Offline
#2
Re: Introduction of Interfaces to Domain Objects
@dmag "From my point of view this is clearly waste of time and we won't actually expose domain objects to the presentation tier also I have a doubt that this breaks the original Exposed Domain Model" pattern."

In general an interface insulates your clients from the concrete classes. There is a school of thought that you should only pass out DTOs that are a copy of your entities to hide them from your clients which is discussed here:

http://www.manning-sandbox.com/thread.jspa?messageID=91995#91995

Certainly I would say not to return interfaces from your Services (note the capital S the to mean the Domain Model service not the façades). I don't think that it is too much of a break of the approach to return interfaces from the façade. This sounds quite subtle - the differences between the Services and the Façades are discussed here:

http://www.manning-sandbox.com/thread.jspa?messageID=92006#92006

In a lot of applications however this seems like code duplication; just as copying to DTOs looks like code duplication. The sorts of applications where that is the case are those which have entities that are logical records in an system that does mainly database CRUD operations on the database. That distinction and how it seems to conflict with some schools of OO thought to expose the fields of your domain entities is discussed here:

http://www.manning-sandbox.com/thread.jspa?messageID=91995#91995