Law of Demeter with data model objects

后端 未结 3 2173
星月不相逢
星月不相逢 2020-12-05 11:33

I came back to work from vacation yesterday, and in our daily standup, my teammates mentioned they were refactoring all of the model objects in our java code to remove all g

3条回答
  •  抹茶落季
    2020-12-05 12:07

    The Law of Demeter about the working with objects, not data structure, in your case DTO as I understand.

    The Law of Demeter explains that you can call methods of objects that are:

    1. Passed as arguments
    2. Cleated locally inside the method
    3. Instance variables (object's fields)
    4. Global

    Data models represent containers with some data inside them that should be shown outside. It's their role and they haven't some other behavior besides this.

提交回复
热议问题