wood burning stoves 2.0*
The moose likes OO, Patterns, UML and Refactoring and the fly likes More about the domain objects in the domain layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "More about the domain objects in the domain layer" Watch "More about the domain objects in the domain layer" New topic
Author

More about the domain objects in the domain layer

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Are domain objects only suppose to have getters and setters or can they have methods as well ??
Example Student domain object would be getters and setters for private variables RollNo,GPA,ContactNo however can it have other methods related to student such as GetResultFromDB() etc ??
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

If you assign other responsibilities to a domain object like fetching from db, then you are violating Single responsibility principle and the design becomes less cohesive.


Mohamed Sanaulla | My Blog
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Mohamed Sanaulla wrote:If you assign other responsibilities to a domain object like fetching from db, then you are violating Single responsibility principle and the design becomes less cohesive.

I completely agree with that. A couple of question come to mind regarding this issue
1-An application theoretically contains domain,service,business and service layer are other layers allowed to access the domain objects or is the service layer only allowed to access them to provide services to other layers

Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Rajesh Khan wrote:
Mohamed Sanaulla wrote:If you assign other responsibilities to a domain object like fetching from db, then you are violating Single responsibility principle and the design becomes less cohesive.

I completely agree with that. A couple of question come to mind regarding this issue
1-An application theoretically contains domain,service,business and service layer are other layers allowed to access the domain objects or is the service layer only allowed to access them to provide services to other layers


I dont know about this, but ideally the layer should communicate with the layer above it or below it and not across other layers. For example you can consider the OSI model of computer networks. If there is a dependency across different layers than changing one of the layers might lead to change in lot of other layers and also it would be not so easy to identify which other layers it would communicate to. I might be wrong, but I drew these conclusions by comparing the concept of layered architecture.

This might partly answer your other query here.
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
In my opinion i think other layers can also access domain objects. Suppose the buisness object wanted to create new domain object so it must be able to access that class. Thats my opinion please correct me if i am wrong..
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

Mohamed's right about adding methods like data access to the domain objects. But what about domain logic? That's a more philosophical question. Classical Object-Oriented methods would put most of the domain logic in the domain objects. But Service Oriented approaches tend to avoid that - they use what I've heard call an "anaemic domain model", where you restrict domain objects to the basics and have all the domain logic provided by your services. Both are valid approaches.

It's also a bit of a philosophical question as to whether you expose the domain objects. In a layered architecture you just need to make sure that all dependencies go downwards - lower layers don't call upper layers. But there's also the concept of a strict layered architecture, where each layer is supposed to depend only on the layer immediately below. It gives you the advantage of reduced coupling (so if you want to replace a layer you only have to consider the one above) at the cost of more infrastructure. I would suggest that updating the domain objects should be forced to go through the service layer, though.

So "it depends" .
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Thanks Matthew, that was quite a lot informative
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Thanks you Matthew and Mohammed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: More about the domain objects in the domain layer
 
Similar Threads
Business Objects(BOs) & Data Transfer Objects(DTOs)-need both ?
Groovy/JSON/sql.Date
Q on Kathy's Mock Test (Topic:encapsulation)
Object responsibility with persistence
Importance of complete Javadoc