Web architecture: MVC, Lazy initialization, Data transfer Objects, Open Session In View, is there a consensus approach?

前端 未结 4 765
醉酒成梦
醉酒成梦 2021-01-20 11:52

What flaws do you see in the following design, (and what would be your ideal architecture suggestion) for a typical web 3-tier application?

My current blueprint appr

4条回答
  •  萌比男神i
    2021-01-20 12:20

    Your above approach sound good.

    But I think you should use UI-Beans. Of course this UI-Bean should be effectively immutable. As soon as it is created its state (and the encapsulated domain object) should not be changed.

    Very simplified example:

    
    class UIBean {
      DomainObject o;
    
      public String getDescription(){
         return trimToSummaryText(o.getDescription());
      }
    
      private static String trimForSummaryText(){
         ....
      }
    }
    
    

    Main pros:

    • Template code tends to get cleaner and consise. Your Frontend-Developer will be happy about this.
    • You don't tend to add frontend-specific helper methods to domain object classes.
    • Grouping of different domain objects or view-beans is possible (ui-bean could have multiple fields). Encapsulation of lists is especially nice here.

    Yes, it involves more java-classes for that. But this abstraction layer is nearly always fine as soon as your webapp and pages grow.

提交回复
热议问题