当前位置 : 主页 > 手机开发 > 其它 >

oop – 封装原则

来源:互联网 收集:自由互联 发布时间:2021-06-19
有一些面向对象的工程原理,它表达了一句话:“一个类只应该知道它作为参数所使用的类的合同,或者它所使用的任何内部合同.” C中的反例是: Foo::bar( Baz* baz){ baz()-blargh()-pants()-soil
有一些面向对象的工程原理,它表达了一句话:“一个类只应该知道它作为参数所使用的类的合同,或者它所使用的任何内部合同.”

C中的反例是:

Foo::bar( Baz* baz)
{
  baz()->blargh()->pants()->soil();  // this is bad, Foo knows about blarghs and pants
}

这个原则有名字吗?而且,实际原则而不是我上面的释义会很高兴看到.

law of demeter感谢 Jim Burger说:

The Law of Demeter (LoD), or Principle of Least Knowledge, is a design guideline for developing software, particularly object-oriented programs. The guideline was invented at Northeastern University towards the end of 1987, and can be succinctly summarized as “Only talk to your immediate friends.” The fundamental notion is that a given object should assume as little as possible about the structure or properties of anything else (including its subcomponents).

网友评论