1
votes

I'm using the current layer topology:

1) dao 2) service 3) controllers(presentation)

In one of my controllers I'm receiving the following call (from clients):

public PlayerStatisticsDTO getPlayerStatistics(int playerId);

The controller should now delegate the call to the service layer.

Problem is, if i create a method like:

public PlayerStatisticsDTO getPlayerStatistics(int playerId);

in my Service I'm actually making my service layer aware of the DTO object!

I believe this is a bad practice (or not?)

So my other alternative that i came up with is creating a new class:

public class PlayerStatistics {...}

and then calling in my controller:

 PlayerStatistics stats = this.service.getPlayerStatistics(playerID);
 return toDTO(stats);

The problem with this solution is that i dont have any use for this class at all in my project so it seems like an unnecessary duplicated code

1
what is your problem i did not understand?Ashish Chaurasia
I dont want to make my service layer familiar with my DTO classesUrbanleg
you want direct access of dto to your controller is't it? what way you want moduralize?Ashish Chaurasia

1 Answers

0
votes

If there is a one on one mapping between the data requested and being presented, using the DTO object in the presentation layer is not a bad practice. If you would change your presentation layer at a later stage, then you can create a new POJO containing the presentation attribute and map them in the service layer.