Yagona javobgarlik tamoyili
Prinsiplar +1 06.08.2023 367

Yagona javobgarlik tamoyili - Wikipedia

Har bir modul yoki sinf faqat bitta mas'uliyatga ega bo'lishi kerak.

"SOLID" tamoyillarining birinchisi. Ushbu tamoyil modullar yoki sinflar bir narsani va faqat bitta narsani bajarishi kerakligini ko'rsatadi. Amaliy ma'noda, bu dasturning xususiyatiga bitta, kichik o'zgartirish faqat bitta komponentni o'zgartirishni talab qilishini anglatadi. Masalan, parolni murakkablik uchun tekshirish usulini o'zgartirish dasturning faqat bitta qismini o'zgartirishni talab qilishi kerak.

Nazariy jihatdan, bu kodni yanada mustahkam va o'zgartirishni osonlashtirishi kerak. O'zgartirilayotgan komponentning yagona mas'uliyati borligini bilish, bu o'zgarishni sinab ko'rish osonroq bo'lishi kerakligini anglatadi. Oldingi misoldan foydalanib, parol murakkabligi komponentini o'zgartirish faqat parol murakkabligi bilan bog'liq xususiyatlarga ta'sir qilishi mumkin. Ko'p mas'uliyatli tarkibiy qismga o'zgartirishning ta'siri haqida fikr yuritish ancha qiyin bo'lishi mumkin.

Shuningdek qarang:

The Single Responsibility Principle
Prinsiplar +1 06.08.2023 367

The Single Responsibility Principle on Wikipedia

Every module or class should have a single responsibility only.

The first of the "SOLID" principles. This principle suggests that modules or classes should do one thing and one thing only. In more practical terms, this means that a single, small change to a feature of a program should require a change in one component only. For example, changing how a password is validated for complexity should require a change in only one part of the program.

Theoretically, this should make the code more robust, and easier to change. Knowing that a component being changed has a single responsibility only means that testing that change should be easier. Using the earlier example, changing the password complexity component should only be able to affect the features which relate to password complexity. It can be much more difficult to reason about the impact of a change to a component which has many responsibilities.

See also: