Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Enterprise Architecture (Spring MVC)

Options
  • 27-11-2015 8:48pm
    #1
    Registered Users Posts: 2,815 ✭✭✭


    I can easily grasp the concept of a three tier system. E.g.
    Presentation (controller)
    Service Layer
    DAO Layer

    ...and that your classes are passed between the layers.

    However, in researching this topic more, I've discovered more layers and class types, and I'm struggling to see how it all fits together.

    Logical Layers
    I've seen the "middle" layer split into a service later and a domain layer, with a preference for a thin service layer. I understand that the service layer (through an interface) would provide an entry point to the model for the controller. However, I'm unsure how you would determine what goes into the service layer and the domain layer, and the distinction between the two.

    Class Types
    Until now(in my non-enterprise student/hobbyist world), I'd have one domain class mapped to one real world object. For example, if I was building a site like imdb, I'd have a Movie domain class which would be used by all of the layers. I've recently discovered data transfer objects (DTO) which I understand are classes with only members/getters/setters (no logic) used to transport data between layers. I'm a little unclear when domain objects are converted to DTOs and vice versa. I assume only the service layer uses domain objects and converts them to DTOs when communicating with the controller and DAO, but I'm unsure.

    I've also seen the phrase "repository bean" (from http://gordondickens.com/wordpress/2012/07/08/enterprise-spring-best-practices-part-2-application-architecture/), and I'm unsure how they differ from DTOs and if they are even commonly used.


    So for a standard insert operation in a Spring MVC enterprise application, I'm assuming the following flow:
    • Controller receives the request with a form backing object, which is a DTO.
    • Controller passes the DTO to the service layer
    • Service layer converts DTO to a domain object and performs any relevant business logic.
    • Service layer then converts domain object back to DTO and passes it to the DAO
    • DAO updates db using the DTO.
    Using this method, it would seem all the annotations used by hibernate / spring validation etc is in the DTO and not the domain object, which is kinda neat.

    So, my questions is - are my assumptions above correct or am I completely wrong? What corrections needs to be made? What exactly is the difference between the service layer and the domain layer - preferably with an example of methods you'd find in each.


    Thanks so much. I know this is a long post.


Comments

  • Registered Users Posts: 7 Profix


    So, you'd only use a DTO to deliver relevant data to a client when they don't have the model. If you have two systems where System A has a FooBar model and System B wants to know some property of a FooBar entity, instead of making a request for that one property value to a controller in System A (and then later likely needing to request another property on the same entity), System A should return a marshaled DTO with the FooBar entity's values.

    The service layer of the system containing the models can interact with the entities directly.

    On logical layers; the way I tend to think of it is the domain layer should have methods for doing one thing to an entity / repository, and the service layer mostly just acts as a proxy to the domain layer - but when you need a method that does multiple things to an entity/entities, you put the logic in the service layer instead of the domain layer. Always depends on the application though.


Advertisement