Is it appropriate to repeat data in models to satisfy using law of demeter in collections?

前端 未结 3 326
囚心锁ツ
囚心锁ツ 2021-01-14 21:06

This is a contrived example, say I want to list the population of a country that a person has a friend in, here are two setups below. Would it be best to repeat data in the

3条回答
  •  执笔经年
    2021-01-14 21:50

    Ahh, the "occasionally useful suggestion of Demeter". (Martin Fowler.)

    I think DIE/DRY and normalization are more fundamental principles, but it's ultimately going to be a contest between conflicting guidelines that you will need to apply common sense to.

    The "law" applied to object classes in one specific project and does have obvious value as a class hierarchy design model.

    But there is controversy over Demeter's application specifically with respect to Rails views. By definition they are a report, and so it is questionable whether the Suggestion of Demeter is applicable.

提交回复
热议问题