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

前端 未结 3 330
囚心锁ツ
囚心锁ツ 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:43

    In my opinion you should avoid repition of data where you can. However, you can create aggregate objects which allow you to combine data. So you can keep your core entities clean but then have additional supporting entities which agreggate objects.

    If you use the example of a View in SQL, you can retrieve a result which is the combination of many entities. This result could be the agreggate entity and is a perfectly legitimate means of 'repeating' data.

提交回复
热议问题