Encapsulation principle

There is some kind of object-oriented engineering principle that formulates something like "a class, should only know about the class contracts that it takes as arguments, or any internal ones that it uses."

Counter example in C ++:

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

Does this principle have a name? In addition, it would be nice to see the actual principle, not my paraphrase above.

+3
source share
4 answers

law demeter thanks Jim Burger He speaks:

(LoD) - , - . - 1987 " ". , - ( ).
+7

(- baz), , . (, , ). : S.O.L.I.D.

, , , . .

0

SOLID. , . , SRP.

- - . . , OO.

0

I would say here that good encapsulation helps reduce coupling - this is a good goal for any decent encapsulation, except obviously.

0
source

Source: https://habr.com/ru/post/1699693/


All Articles