Law of Demeter - Data objects

前端 未结 5 1283
青春惊慌失措
青春惊慌失措 2021-02-06 01:28

I\'m trying to follow the Law Of Demeter ( see http://en.wikipedia.org/wiki/Law_of_Demeter , http://misko.hevery.com/code-reviewers-guide/flaw-digging-into-collaborators/ ) as I

5条回答
  •  庸人自扰
    2021-02-06 01:57

    You're correct and you'll most likely model your value objects something like this

    class Order {
        User user;
    }
    
    class User {
        Address shippingAddress;
        Address deliveryAddress;
    }
    
    class Address {
        String city;
        ...
    }
    

    When you start considering how you will persist this data to a database (e.g. ORM) do you start thinking about performance. Think eager vs lazy loading trade offs.

提交回复
热议问题