Кіріспе
Бағдарламалық жасақтама объектіге бағытталған жобалау әдістемесі. Объектіге бағытталған жобалауда тәуелділік инверсиясы принципі – бұл байланысы төмен бағдарламалық модульдер үшін арнайы әдістеме. Бұл принципті қолданғанда, жоғары деңгейдегі, саясатты белгілейтін модульдерден төмен деңгейдегі, тәуелділік модульдеріне орнатылған дәстүрлі тәуелділік қатынастары кері қайтылып, жоғары деңгейдегі модульдерді төмен деңгейдегі модульдің іске асыру егжей-тегжейлерінен тәуелсіз етеді. Принцип былай тұжырымдайды:
In object oriented design, the dependency inversion principle is a specific methodology for loosely coupled software modules. When following this principle, the conventional dependency relationships established from high level, policy setting modules to low level, dependency modules are reversed, thus rendering high level modules independent of the low level module implementation details. The principle states:
By dictating that both high level and low level objects must depend on the same abstraction, this design principle inverts the way some people may think about object oriented programming. The idea behind points A and B of this principle is that when designing the interaction between a high level module and a low level one, the interaction should be thought of as an abstract interaction between them. This not only has implications on the design of the high level module, but also on the low level one: the low level one should be designed with the interaction in mind and it may be necessary to change its usage interface. In many cases, thinking about the interaction in itself as an abstract concept allows the coupling of the components to be reduced without introducing additional coding patterns, allowing only a lighter and less implementation dependent interaction schema. When the discovered abstract interaction schema(s) between two modules is/are generic and the generalization makes sense, this design principle also leads to the following dependency inversion coding pattern.
Жоғары және төмен деңгейдегі нысандардың барлығы бір абстракцияға тәуелді болуы керек. Бұл жобалау принципі кейбір адамдардың объектіге бағытталған бағдарламалау туралы ойлау жолын өзгертеді. Принциптің А және В тармақтарының мәні – жоғары деңгейдегі модуль мен төмен деңгейдегі модульдің өзара әрекеттесуін жобалау кезінде, олардың арасындағы өзара әрекеттесу абстрактілі түрде қарастырылуы керек. Бұл тек жоғары деңгейдегі модульдің дизайнына ғана емес, төмен деңгейдегі модульге де әсер етеді: төмен деңгейдегі модуль өзара әрекеттесуді ескере отырып жобаланып, оның қолданыс интерфейсін өзгерту қажет болуы мүмкін. Көп жағдайда, өзара әрекеттесуді абстрактілі ұғым ретінде қарастыру компоненттердің байланысын қосымша кодтау үлгілерін қолданбай азайтуға мүмкіндік береді, нәтижесінде жеңіл және іске асыруға аз тәуелді өзара әрекеттесу схемасы пайда болады. Егер екі модуль арасындағы анықталған абстрактілі өзара әрекеттесу схемасы жалпыланған болса және жалпылау мағыналы болса, бұл жобалау принципі келесі тәуелділік инверсиясы кодтау үлгісіне алып келеді.
In object oriented design, the dependency inversion principle is a specific methodology for loosely coupled software modules. When following this principle, the conventional dependency relationships established from high level, policy setting modules to low level, dependency modules are reversed, thus rendering high level modules independent of the low level module implementation details. The principle states:
By dictating that both high level and low level objects must depend on the same abstraction, this design principle inverts the way some people may think about object oriented programming. The idea behind points A and B of this principle is that when designing the interaction between a high level module and a low level one, the interaction should be thought of as an abstract interaction between them. This not only has implications on the design of the high level module, but also on the low level one: the low level one should be designed with the interaction in mind and it may be necessary to change its usage interface. In many cases, thinking about the interaction in itself as an abstract concept allows the coupling of the components to be reduced without introducing additional coding patterns, allowing only a lighter and less implementation dependent interaction schema. When the discovered abstract interaction schema(s) between two modules is/are generic and the generalization makes sense, this design principle also leads to the following dependency inversion coding pattern.
Дәстүрлі қабаттар үлгісі
Дәстүрлі қолданба архитектурасында төменгі деңгейдегі компоненттер (мысалы, Пайдалылық қабаты) жоғары деңгейдегі компоненттер (мысалы, Саясат қабаты) пайдалану үшін жасалады, бұл күрделі жүйелерді құруға мүмкіндік береді. Мұндай құрамда жоғары деңгейдегі компоненттер белгілі бір міндетті орындау үшін төменгі деңгейдегі компоненттерге тікелей тәуелді болады. Төменгі деңгейдегі компоненттерге тәуелділік жоғары деңгейдегі компоненттерді қайта пайдалану мүмкіндіктерін шектейді. Ал тәуелділік инъекциясы жоғары деңгейдегі компонентке қажетті төменгі деңгейдегі компоненттің нақты іске асырылуын жүктеуді жеңілдету үшін қолданылады.
Тарих
Тәуелділік инверсиясы принципі Роберт К. Мартинмен ұсынылып, бірнеше жариялымдарда, оның ішінде "Объектіге бағытталған дизайн сапасының өлшемдері: тәуелділіктерді талдау" мақаласында, 1996 жылғы маусымдағы C++ баяндамасында жарияланған "Тәуелділік инверсиясы принципі" атты мақаласында, сондай-ақ "Agile Software Development, Principles, Patterns, and Practices" және "Agile Principles, Patterns, and Practices in C#" кітаптарында сипатталған.