Interfeyslarga bo`lish tamoyili
Prinsiplar +4 06.08.2023 695

Interfeyslarga bo`lish tamoyili - Wikipedia

Hech bir mijoz o'zi ishlatmaydigan usullarga qaram bo'lishga majburlanmasligi kerak.

"SOLID" tamoyillarining to'rtinchisi. Ushbu printsip komponentning iste'molchilari aslida foydalanmayotgan komponentning funktsiyalariga bog'liq bo'lmasligi kerakligini bildiradi.

Misol tariqasida, bizda faylni ifodalovchi tuzilmadan XML hujjatini o'qish usuli borligini tasavvur qiling. U faqat baytlarni o'qishi, faylda oldinga yoki orqaga siljishi kerak. Agar fayl tuzilmasining bog'liq bo'lmagan xususiyati o'zgarganligi sababli ushbu usulni yangilash kerak bo'lsa (masalan, fayl xavfsizligini ifodalash uchun foydalaniladigan ruxsatlar modelining yangilanishi), u holda printsip bekor qilingan. Fayl uchun "seekable-stream" interfeysini amalga oshirish va XML o'quvchi uchun undan foydalanish yaxshiroq bo'lar edi.

Ushbu tamoyil ob'ektga yo'naltirilgan dasturlash uchun alohida ahamiyatga ega, bu erda interfeyslar, ierarxiyalar va mavhum turlar turli komponentlar orasidagi bog'lanishni minimallashtirish uchun ishlatiladi. Duck typing - bu aniq interfeyslarni yo'q qilish orqali ushbu printsipni amalga oshiradigan metodologiya.

Shuningdek qarang:

The Interface Segregation Principle
Prinsiplar +4 06.08.2023 695

The Interface Segregation Principle on Wikipedia

No client should be forced to depend on methods it does not use.

The fourth of the 'SOLID' principles. This principle states that consumers of a component should not depend on functions of that component which it doesn't actually use.

As an example, imagine we have a method which reads an XML document from a structure which represents a file. It only needs to read bytes, move forwards or move backwards in the file. If this method needs to be updated because an unrelated feature of the file structure changes (such as an update to the permissions model used to represent file security), then the principle has been invalidated. It would be better for the file to implement a 'seekable-stream' interface, and for the XML reader to use that.

This principle has particular relevance for object-oriented programming, where interfaces, hierarchies and abstract types are used to minimise the coupling between different components. Duck typing is a methodology which enforces this principle by eliminating explicit interfaces.

See also: