Law of Demeter - Data objects

前端 未结 5 1282
青春惊慌失措
青春惊慌失措 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:46

    The Law Of Demeter is about calling methods, not accessing properties/fields. I know technically properties are methods, but logically they're meant to be data. So, your example of order.user.address.city seems fine to me.

    This article is interesting further reading: http://haacked.com/archive/2009/07/13/law-of-demeter-dot-counting.aspx

提交回复
热议问题