public class BigPerformance { public decimal Value { get; set; } } public class Performance { public BigPerformance BigPerf { get; set; } } public class Category { public Performance Perf { get; set; } }
如果我打电话:
Category cat = new Category(); cat.Perf.BigPerf.Value = 1.0;
我认为这打破了Law of Demeter / Principle of Least Knowledge?
如果是这样,如果我有大量的内部类属性,我该如何解决这个问题呢?
解决方法
Martin Fowler最喜欢的一句话:
I’d prefer it to be called the
Occasionally Useful Suggestion of
Demeter
http://haacked.com/archive/2009/07/14/law-of-demeter-dot-counting.aspx