Liskovning o'rin almashtirish tamoyili
Prinsiplar 0 06.08.2023 234

Liskovning o'rin almashish tamoyili on Wikipedia

Tizimni buzmasdan turni pastki turga almashtirish mumkin bo'lishi kerak.

"SOLID" tamoyillarining uchinchisi. Ushbu tamoyil shuni ko'rsatadiki, agar komponent bir turga tayansa, u tizimning ishlamay qolishi yoki ushbu kichik turning tafsilotlarini bilmasdan turib, ushbu turdagi kichik turlardan foydalanish imkoniyatiga ega bo'lishi kerak.

Misol tariqasida, bizda faylni ifodalovchi tuzilmadan XML hujjatini o'qish usuli borligini tasavvur qiling. Agar usul asosiy turdagi "fayl" dan foydalansa, u holda "fayl" dan kelib chiqadigan har qanday narsa funktsiyada ishlatilishi kerak. Agar "fayl" teskari qidirishni qo'llab-quvvatlasa va XML tahlilchisi bu funktsiyadan foydalansa, lekin teskari qidirishga urinishda olingan "tarmoq fayli" turi muvaffaqiyatsiz bo'lsa, "tarmoq fayli" printsipni buzgan bo'ladi.

Ushbu tamoyil ob'ektga yo'naltirilgan dasturlash uchun alohida ahamiyatga ega, bunda tizim foydalanuvchilarini chalkashtirib yubormaslik uchun tip ierarxiyasini diqqat bilan modellashtirish kerak.

Shuningdek qarang:

The Liskov Substitution Principle
Prinsiplar 0 06.08.2023 234

The Liskov Substitution Principle on Wikipedia

It should be possible to replace a type with a subtype, without breaking the system.

The third of the 'SOLID' principles. This principle states that if a component relies on a type, then it should be able to use subtypes of that type, without the system failing or having to know the details of what that subtype is.

As an example, imagine we have a method which reads an XML document from a structure which represents a file. If the method uses a base type 'file', then anything which derives from 'file' should be usable in the function. If 'file' supports seeking in reverse, and the XML parser uses that function, but the derived type 'network file' fails when reverse seeking is attempted, then the 'network file' would be violating the principle.

This principle has particular relevance for object-oriented programming, where type hierarchies must be modeled carefully to avoid confusing users of a system.

See also: