This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Controller to Service Layer

 
Kev Adams
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic