As an example, if there is a controller that calls a CountryService class and the CountryService class uses a Countries class, should the CountryService return the CountriesClass to the controller? Or should the service have another DTO type that contains information about Countries but is only used by the presentation layer and give that to the controller instead?


This depends on your application architecture. For example:

  • in the original MVC, the controller and the view are both allowed to access model objects.
  • in MVP, the controller acts as middleman (which enables the model to be on a remote server), so in this case you'd rather expect some DTO objects to be used.

But it depends also on semantics of your objects:

  • can your Country objects be cloned (locally, or remotely via seralization/deserialization) because they only contain copy of a fixed state (e.g. Country name, official languages, currency) ?
  • or is your Country an object which is unique, and which can have its state potentially updated by events outside your application (e.g an estimation of the population based on a model that estimates population growth every second, or simply because several clients could update the object concurrently) ?

In the latter case, you'd definitively never manipulate a model object: you'd need to work with a DTO, or a proxy object and use some identity mapper. But this will immediately make the problem more complex, raising the question of optimistic vs pessimistic concurrency handling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.