You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. High-level modules should not depend on low-level modules. Both should
1501
-
depend on abstractions.
1502
-
2. Abstractions should not depend upon details. Details should depend on
1503
-
abstractions.
1504
-
1505
-
This can be hard to understand at first, but if you've worked with AngularJS,
1506
-
you've seen an implementation of this principle in the form of Dependency
1507
-
Injection (DI). While they are not identical concepts, DIP keeps high-level
1508
-
modules from knowing the details of its low-level modules and setting them up.
1509
-
It can accomplish this through DI. A huge benefit of this is that it reduces
1510
-
the coupling between modules. Coupling is a very bad development pattern because
1511
-
it makes your code hard to refactor.
1512
-
1513
-
As stated previously, JavaScript doesn't have interfaces so the abstractions
1514
-
that are depended upon are implicit contracts. That is to say, the methods
1515
-
and properties that an object/class exposes to another object/class. In the
1516
-
example below, the implicit contract is that any Request module for an
1517
-
`InventoryTracker` will have a `requestItems` method.
1499
+
Այս սյզբունքը հասմանում է երկու հիմնական բան՝
1500
+
1. Բարձր կարգի մոդուլները չպիտի կախվածություն ունենան ցածր կարգի մոդուլներից։ Երկուսն էլ պիտի կախված կլինեն աբստրակցիաներից։
1501
+
2. Աբստրակցիաները չպիտի կախված լինեն մանրամասնություններից, մանրամասնությունները պիտի կախված լինեն աբստրակցիաներից։
1502
+
1503
+
Սա սկզբից դժվար հասկանալի է, բայց եթե դու աշխատել ես AngularJS֊ով, ապա տեսել ես այս սկբունքի իրականացումը Կախվածության Ներարկման (Dependency Injection (DI)) տեսքով։ Չնայած որ DI֊ն և DIP-ը նույնական գաղափարներ չեն , DIP֊ը թաքցնում է ցածր կագի մոդուլների իրականացման մանրամասները բարձր կարգի մոդուլներից։ Դա կարող է արվել DI֊ի միջոցով։ Այս մեթոդի օգտագործումը թուլացնում է շղթայակցումը մոդուլների միջև։ Մոդուլների շղթայակցումը շատ վատ նախագծման եղանակ է,որովհետև այն դժվարեցնում է կոդի վերափոխումը (refactoring)։
1504
+
1505
+
Ինչպես նախկինում նշվեց JavaScript֊ը չուն ինտերֆեյսներ, հետևաբար աբստրակցիաները անուղակի պայմանագրերի վրա են հիմնվում։ Այսինքն մի կլասից/օբյեկտից մյուսին փոխանցվող մեթոդները և հատկանիշները։ Հաջորդ օրինակում անուղակի պայմանագիրը այն է, որ `InventoryTracker`֊ի համար Request մոդուլը պիտի ունենա `requestItems` մեթոդը։
0 commit comments