Demeter qonuni
Qonunlar +1 06.08.2023 192

Demeter qonuni Wikipedia

Notanishlar bilan gaplashmang.

Demeter qonuni, shuningdek, "Eng kam bilim printsipi" sifatida ham tanilgan, dasturiy ta'minotni loyihalash printsipi, ayniqsa ob'ektga yo'naltirilgan tillarda tegishli.

Unda aytilishicha, dasturiy ta'minot birligi faqat o'zining bevosita hamkorlari bilan gaplashishi kerak. B ob'ektga havolasi bo'lgan A ob'ekti o'z usullarini chaqirishi mumkin, lekin agar B ob'ekt C ob'ektiga havolaga ega bo'lsa, A Cs usullarini chaqirmasligi kerak. Shunday qilib, agar C doThing() usuliga ega bo'lsa, A uni to'g'ridan-to'g'ri chaqirmasligi kerak; B.getC().doThis().

Ushbu printsipga rioya qilish o'zgarishlar doirasini cheklaydi, bu esa ularni kelajakda osonroq va xavfsizroq qiladi.

The Law of Demeter
Qonunlar +1 06.08.2023 192

The Law of Demeter on Wikipedia

Don't talk to strangers.

The Law of Demeter, also known as "The Principle of Least Knowledge" is a principle for software design, particularly relevant in object orientated languages.

It states that a unit of software should talk only to its immediate collaborators. An object A with a reference to object B can call its methods, but if B has a reference to object C, A should not call Cs methods. So, if C has a doThing() method, A should not invoke it directly; B.getC().doThis().

Following this principal limits the scope of changes, making them easier and safer in future.