Should Enterprise Java entities be dumb?

前端 未结 8 604
醉酒成梦
醉酒成梦 2020-12-02 14:32

In our legacy Java EE application, there are loads of value object (VO) classes which typically contain only getters and setters, maybe equals() and hashC

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 15:08

    The main problem with adding logic to those classes is, they would need more attributes to keep track the object state, and these extra attributes generally do not need to be serialized. This means extra work is needed in the serialization mechanism of those classes.

    Considering that many projects have a mixture of jr. programmers and sr. programmers and most of the work is performed by the jr's who don't understand ( or care ) about optimal serialization, it is much more easy to have this plain old java objects as "value objects" which pretty much just pass and receive data and put the logic in other place.

    If you manage to have an architecture where the logic is placed in a business object ( that is VO + Logic ) I think that would be better also. Just bear in mind the whole team is in the same page and they don't duplicate code and logic ( which never happens right? )

    Short answer: No, they should not be dumb always, but is a much easier to have them that way.

提交回复
热议问题