Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think it belongs in controller - that's really part of the view, which can come and go. The business logic and persistence shouldn't depend on view or controller.</p> <p>A separate service layer gives you the chance to expose that logic as distributed components to non-browser based clients (e.g., mobile views, batch processing, etc.)</p> <p>I wouldn't have the model extend the data store in an object-oriented sense, because inheritance is an IS-A relationship. As you've noted, the model is not a relational database; that's merely one choice among many for persisting information.</p> <p>I think it's more composition. The persistence layer could be a separate DAO that persists model objects without requiring that they be aware of the fact that they are longer-lived. OR you have mixin behavior where a model advertises the fact that it has CRUD operations, but it merely passes off requests to the implementation they're given.</p> <p>The usual Spring idiom would have a service layer that's separate from the controller. It knows about use cases and units of work. It uses model and persistence objects to accomplish the goals of the use case.</p> <p>MVC implies three actors. I would say there are more layers than that in a typical application - persistence and service need to be added.</p> <p>UPDATE: </p> <p>If the model object does not import anything from the persistence package, then it has no knowledge of it whatsoever. Here's a simple example, using a simple model class Person and its DAO interface, each in its own package:</p> <pre><code>package persistence.model; public class Person { private String name; public Person(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } } </code></pre> <p>Note that the DAO interface imports the model package, but not the other way around:</p> <pre><code>package persistence.persistence; import persistence.model.Person; import java.util.List; public interface PersonDao { Person find(Long id); List&lt;Person&gt; find(); void saveOrUpdate(Person p); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload