gpt4 book ai didi

c# - 如何修改代码以使其遵守 Demeter 法则

转载 作者:太空狗 更新时间:2023-10-29 21:00:07 24 4
gpt4 key购买 nike

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

关于c# - 如何修改代码以使其遵守 Demeter 法则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2666930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com