Meaningless Drivel is fun!*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Controller to Service Layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Controller to Service Layer " Watch "Controller to Service Layer " New topic
Author

Controller to Service Layer

Kev Adams
Greenhorn

Joined: Oct 27, 2009
Posts: 23
I've been struggling with a proper way to get my controller to talk to my service layer. It's not that I can't get the two to talk, it's that I want to make sure that there are no dependencies between the layers

Specifically, what happens when you want to call some sort of "create" method in your service layer?

I'm using Struts2 as my controller. Here's a simple example



Here's a simple service:


The question is, what goes in the controller's (action's) call to the service? (i.e. line 15 in the action)
If you build a domain object in the controller and pass it to the service, then what's the point? You'd have to import the domain object into the controller and you could just call the business methods directly from the domain object.
If you make the service's createXxxx method accept a bunch of primitives, then you could end up with a very big parameter list, which is bad too.

Thanks in advance
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
First, you wouldn't build any domain/business model objects in a MVC-based Controller. This is not how the MVC pattern works.

Keep in mind that objects contain data AND behavior.

The Business Delegate pattern will show you a way to connect a Controller to the business object model.

http://java.sun.com/blueprints/corej2eepatterns/Patterns/BusinessDelegate.html
Kev Adams
Greenhorn

Joined: Oct 27, 2009
Posts: 23
Jimmy Clark wrote:Also, it is unclear why you have a "service" object and a "domain/model" object. What is the difference between them?


The domain/model object contains my business logic. The service object is a thin layer over the domain object, as referenced in PoEAA's Service Layer pattern.

Keep in mind that objects contain data AND behavior.


Yep. I was simplifying the example because my domain object has that. The service layer doesn't really have any business logic.

The Business Delegate pattern will show you a way to connect a Controller to the business object model.


Thanks a bunch. I'll check that out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Controller to Service Layer