当归配什么不上火| 拉屎拉出血是什么原因| 大便干硬是什么原因| 艺高胆大是什么生肖| 大小脸去医院挂什么科| 窝窝头是用什么做的| 拔牙有什么危害| 异常的反义词是什么| 阳萎早谢吃什么药最好| 重睑术是什么意思| 尿生化是查什么的| 六味地黄丸有什么功效| 倒霉是什么意思| 三重一大是什么内容| 萧墙是什么意思| 马口鱼是什么鱼| 家里为什么有蜈蚣| 肝脏的作用是什么| 鱼工念什么| 定妆喷雾什么时候用| 无名指比食指长代表什么| 眼睛充血用什么眼药水好| 海松茸是什么| 天癸是什么意思| 如果你是什么那快乐就是什么| 铅中毒是什么引起的| 拉肚子发烧吃什么药| 银红色是什么颜色| 中央委员是什么级别| 阿玛尼是什么品牌| 电饭煲什么牌子好| 纸片人什么意思| 什么级别可以配秘书| 饕餮是什么| 脚心疼痛是什么原因引起的| 吃什么药| beacon什么意思| 牛皮糖是什么意思| 什么是邪淫| 骨骼清奇什么意思| gdp是什么意思| 自然是什么意思| 直视是什么意思| 看望病人买什么东西好| 高就什么意思| 晚上睡不着什么原因| 高温什么时候结束| 25是什么意思| 亚甲炎是什么病| 耳堵耳闷是什么原因| 活好的女人有什么表现| 肝血不足吃什么药| 598分能上什么大学| 红颜知己什么意思| 左肾轻度积水是什么意思| 胎儿没有胎心是什么原因| europe是什么意思| 荞麦长什么样子| 2010是什么年| 舌系带挂什么科| 蓝色小药丸是什么| 孩子睡觉磨牙是什么原因| 儿童咳嗽挂什么科| 钓是什么意思| 痹是什么意思| 连号的钱为什么不能花| 梦见拉屎是什么意思| camper是什么牌子| 电饭锅内胆什么材质好| 女性得疱疹是什么症状| 吃什么精力旺盛有精神| 幽门螺旋杆菌挂什么科| 橄榄色是什么颜色| 办理身份证需要什么| 荨麻疹去药店买什么药| 喷塑工是干什么的| 什么可以误诊为畸胎瘤| 牡蛎是什么东西| 鹿的角像什么| 什么叫有氧运动| 怕冷不怕热是什么体质| 性病是什么症状| coach是什么意思| 血糖高吃什么降血糖| 扁桃体肿大吃什么药好| 须尽欢什么意思| 吃什么愈合伤口恢复最快| kpi是什么意思| 符号是什么意思| 高血糖挂什么科室的号| 36d什么意思| 2月2号什么星座| 游泳为什么要穿泳衣| 脾胃不好有什么症状表现| 抗核抗体阳性对怀孕有什么影响| 刘诗诗是什么样的人| 向日葵什么时候采摘| 指模是什么意思| 内向是什么意思| 外阴白斑是什么引起的| 草鱼吃什么草| 双子女和什么星座最配| 病人化疗期间吃什么好| 过期红酒有什么用途| 红男绿女是什么生肖| 甍是什么意思| 脾虚喝什么泡水比较好| 梦见吃李子是什么意思| 胃不消化吃什么药好| 吃什么对皮肤好| 杏色配什么颜色好看| 为什么会吐| 脑白质病变是什么病| 阳光像什么| 白斑不能吃什么| 腱鞘炎吃什么药好使| 跖疣是什么| 易孕期是什么意思| 躯体化什么意思| 咳嗽有黄痰吃什么消炎药| 男人什么脸型最有福气| 早上9点到10点是什么时辰| 焦虑症吃什么中成药能根治| 子衿什么意思| 脸上长闭口是什么原因导致的| 为什么晚上不能晾衣服| 福生无量天尊什么意思| 女人长期做俯卧撑有什么效果| 夏天可以玩什么| 什么是polo衫| 丽珠兰是什么| 女性手麻是什么原因| 手脱皮是缺什么维生素| 什么是钙化灶| 那好吧是什么意思| 热脸贴冷屁股是什么意思| 属狗男和什么属相最配| 血糖高可以吃什么肉类| 愚钝是什么意思| 看肺挂什么科| 鸡伸脖子张嘴用什么药| 细菌性痢疾症状是什么| 男孩什么时辰出生最好| 鼻炎吃什么| 史迪奇是什么动物| 为什么喝纯牛奶会拉肚子| 金乌是什么| 食管裂孔疝是什么意思| 一什么花瓣| 咳咳是什么意思| 卵巢囊性回声什么意思| 感冒挂什么科室| 尿酮体是什么| 脑白质变性是什么病| 芥末是什么味道| 转氨酶高是什么| 沉的右边念什么| 先天性一个肾对人有什么影响| 为什么一进去就软了| 脑血管堵塞吃什么药最好| 什么原因导致荨麻疹| 十二月是什么星座| 头晕看什么科| 懿代表什么意思| 草酸是什么| 谷丙转氨酶高吃什么药可以降下来| 什么叫全科医生| 肌酐低是什么问题| 老人说胡话是什么征兆| 丹五行属性是什么| 2月2日是什么星座| 意难平什么意思| 福相是什么意思| 桂圆补什么| 吃什么助勃药能硬| 为什么微信运动总是显示步数为0| 钙盐是什么| 四级士官是什么级别| 林俊杰什么时候出道的| 我国计划生育什么时候开始| 热火朝天是什么生肖| 二月九号是什么星座| 什么叫便溏| icicle是什么牌子| 何其是什么意思| 多核巨细胞是什么意思| 东四命是什么意思| 7月11日是什么日子| 不结婚的叫什么族| 人中黄是什么| 终而复始什么意思| 老年人脚肿什么原因| 1月18日什么星座| 血糖高能喝什么饮料| 呢是什么意思| 仓鼠吃什么东西| 螃蟹喜欢吃什么食物| 血管瘤是什么样子的| 今天什么日子| 趋势是什么意思| 艾滋病有什么症状图片| 孕妇拉肚子是什么原因引起的| 红细胞压积偏高是什么原因| 胸小是什么原因| 糖尿病筛查做什么检查| 强颜欢笑是什么意思| 什么是动脉硬化| ad滴剂什么牌子好| 海带为什么要打结| 梦见老板是什么意思| 狗到家里是什么预兆| 口干口苦口臭是什么原因引起的| 照影是什么意思| 正连级是什么军衔| 什么的季节| 卵巢囊性回声什么意思| 商朝后面是什么朝代| 屎发黑是什么原因| 弥散是什么意思| 弦子为什么嫁给李茂| 血小板偏高有什么危害| 室上速是什么病| 狗被蜱虫咬了有什么症状| 腋下是什么经络| 蚊子吸血是为了什么| zoey是什么意思| 内膜厚是什么原因引起的| 白带是什么| 原发性高血压什么意思| 羟氯喹是什么药| 额头老出汗是什么原因| 三伏贴什么时候贴| 补锌吃什么| 油价什么时候上涨| 吃什么可以丰胸| 磕头虫吃什么| cp什么意思网络用语| 弱阳性和阳性有什么区别| 咬牙切齿什么意思| 清洁度三度是什么炎症| 大虾不能和什么一起吃| praal00是什么型号| 多潘立酮片治什么病| 蛋蛋冰凉潮湿什么原因| 前列腺是什么| 基点是什么意思| 连云港有什么好吃的| 六十六大寿有什么讲究| 康庄大道是什么意思| 淋巴发炎挂什么科| 拔牙能吃什么| cook是什么意思| 造血干细胞是什么| 4.12是什么星座| 小孩突然头疼是什么原因| 腱鞘炎用什么药| 吃什么可以快速排便| 抽烟什么感觉| 什么叫越位| 可甜可盐什么意思| 3的倒数是什么| 牙齿疼是什么原因引起的| sjb是什么意思| 肩周炎用什么药好| 百度Jump to content

全国政协委员徐里:让传统文化为青少年注入文化自信

From Wikipedia, the free encyclopedia
百度   无穷  数学家相信无穷的存在,他们还认为,不仅存在无穷,而且还存在很多种无穷。

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:[1]

  1. High-level modules should not import anything from low-level modules. Both should depend on abstractions (e.g., interfaces).
  2. Abstractions should not depend on details. Details (concrete implementations) should depend on abstractions.

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.[2]

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 has implications for the design of both the high-level and the low-level modules: 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 itself as an abstract concept allows for reduction of the coupling between the components without introducing additional coding patterns and results in a lighter and less implementation-dependent interaction schema. When this abstract interaction schema is generic and clear, this design principle leads to the dependency inversion pattern described below.

Traditional layers pattern

[edit]

In conventional application architecture, lower-level components (e.g., Utility Layer) are designed to be consumed by higher-level components (e.g., Policy Layer) which enable highly composite systems to be built. Here higher-level components depend directly upon lower-level components to achieve some task. This dependency upon lower-level components limits the reuse opportunities of the higher-level components.[1]

The goal of the dependency inversion pattern is to avoid this highly coupled distribution with the mediation of an abstract layer, and to increase the reusability of higher and policy layers.

Dependency inversion pattern

[edit]

With the introduction of an abstract layer, both high- and lower-level layers reduce the traditional dependencies from top to bottom. Nevertheless, the "inversion" concept does not mean that lower-level layers directly depend on higher-level layers. Rather, both layers should depend on abstractions (interfaces) that expose the behavior needed by higher-level layers.

In a direct application of dependency inversion, the abstracts are owned by the higher/policy layers. This architecture groups the higher/policy components and the abstractions that define lower services together in the same package. The lower-level layers are created by inheritance/implementation of these abstract classes or interfaces.[1]

The inversion of the dependencies and ownership encourages reuse of the higher and policy layers. Upper layers could use other implementations of the lower services. When the lower-level layer components are closed or when the application requires the reuse of existing services, it is common that an Adapter mediates between the services and the abstractions.

Dependency inversion pattern generalization

[edit]

In many projects the dependency inversion principle and pattern are considered as a single concept that should be generalized, i.e., applied to all interfaces between software modules. There are at least two reasons for that:

  1. It is simpler to see a good thinking principle as a coding pattern. Once an abstract class or an interface has been coded, the programmer may say: "I have done the job of abstraction".
  2. Because many unit testing tools rely on inheritance to accomplish mocking, the usage of generic interfaces between classes (not only between modules when it makes sense to use generality) became the rule.

If the mocking tool used relies only on inheritance, it may become necessary to widely apply the dependency inversion pattern. This has major drawbacks:

  1. Merely implementing an interface over a class isn't sufficient to reduce coupling; only thinking about the potential abstraction of interactions can lead to a less coupled design.
  2. Implementing generic interfaces everywhere in a project makes it harder to understand and maintain. At each step the reader will ask themself what are the other implementations of this interface and the response is generally: only mocks.
  3. The interface generalization requires more plumbing code, in particular factories that generally rely on a dependency-injection framework.
  4. Interface generalization also restricts the usage of the programming language.

Generalization restrictions

[edit]

The presence of interfaces to accomplish the Dependency Inversion Pattern (DIP) has other design implications in an object-oriented program:

  • All member variables in a class must be in interfaces or abstracts.
  • All concrete class packages must connect only through interface or abstract class packages.
  • No class should derive from a concrete class.
  • No method should override an implemented method.[1]
  • All variable instantiation requires the implementation of a creational pattern such as the factory method or the factory pattern, or the use of a dependency-injection framework.

Interface mocking restrictions

[edit]

Using inheritance-based mocking tools also introduces restrictions:

  • Static externally visible members should systematically rely on dependency injection making them far harder to implement.
  • All testable methods should become an interface implementation or an override of an abstract definition.

Implementations

[edit]

Two common implementations of DIP use similar logical architecture but with different implications.

A direct implementation packages the policy classes with service abstracts classes in one library. In this implementation high-level components and low-level components are distributed into separate packages/libraries, where the interfaces defining the behavior/services required by the high-level component are owned by, and exist within the high-level component's library. The implementation of the high-level component's interface by the low-level component requires that the low-level component package depend upon the high-level component for compilation, thus inverting the conventional dependency relationship.

Figures 1 and 2 illustrate code with the same functionality, however in Figure 2, an interface has been used to invert the dependency. The direction of dependency can be chosen to maximize policy code reuse, and eliminate cyclic dependencies.

In this version of DIP, the lower layer component's dependency on the interfaces/abstracts in the higher-level layers makes reuse of the lower layer components difficult. This implementation instead "inverts" the traditional dependency from top-to-bottom to the opposite, bottom-to-top.

A more flexible solution extracts the abstract components into an independent set of packages/libraries:

The separation of each layer into its own package encourages reuse of any layer, providing robustness and mobility.[1]

Examples

[edit]

Genealogical module

[edit]

A genealogical system may represent relationships between people as a graph of direct relationships between them (father-son, father-daughter, mother-son, mother-daughter, husband-wife, wife-husband, etc.). This is very efficient and extensible, as it is easy to add an ex-husband or a legal guardian.

But some higher-level modules may require a simpler way to browse the system: any person may have children, parents, siblings (including half-brothers and -sisters or not), grandparents, cousins, and so on.

Depending on the usage of the genealogical module, presenting common relationships as distinct direct properties (hiding the graph) will make the coupling between a higher-level module and the genealogical module much lighter and allow changing the internal representation of the direct relationships completely without any effect on the modules using them. It also permits embedding exact definitions of siblings or uncles in the genealogical module, thus enforcing the single responsibility principle.

Finally, if the first extensible generalized graph approach seems the most extensible, the usage of the genealogical module may show that a more specialized and simpler relationship implementation is sufficient for the application(s) and helps create a more efficient system.

In this example, abstracting the interaction between the modules leads to a simplified interface of the lower-level module and may lead to a simpler implementation of it.

Remote file server client

[edit]

A remote file server (FTP, cloud storage ...) client can be modeled as a set of abstract interfaces:

  1. Connection/Disconnection (a connection persistence layer may be needed)
  2. Folder/tags creation/rename/delete/list interface
  3. File creation/replacement/rename/delete/read interface
  4. File searching
  5. Concurrent replacement or delete resolution
  6. File history management ...

If local and remote files offers the same abstract interfaces, high-level modules that implement the dependency inversion pattern can use them indiscriminately. The application will be able to save its documents locally or remotely transparently.

The level of service required by high level modules should be considered.

Designing a module as a set of abstract interfaces, and adapting other modules to it, can provide a common interface for many systems.

Model–view–controller

[edit]
Example of DIP
Example of DIP

UI and ApplicationLayer packages contain mainly concrete classes. Controllers contains abstracts/interface types. UI has an instance of ICustomerHandler. All packages are physically separated. In the ApplicationLayer there is a concrete implementation of CustomerHandler that Page class will use. Instances of the ICustomerHandler interface are created dynamically by a Factory (possibly in the same Controllers package). Concrete types Page and CustomerHandler depend on ICustomerHandler, not on each other.

Since the UI doesn't reference the ApplicationLayer or any other concrete package implementing ICustomerHandler, the concrete implementation of CustomerHandler can be replaced without changing the UI class. Also, the Page class implements interface IPageViewer which could be passed as an argument to ICustomerHandler methods, allowing the concrete implementation of CustomerHandler to communicate with UI without a concrete dependency. Again, both are linked by interfaces.

[edit]

Applying the dependency inversion principle can also be seen as an example of the adapter pattern. That is, the high-level class defines its own adapter interface which is the abstraction on which the other high-level classes depend. The adapted implementation also depends necessarily on the same adapter interface abstraction, while it can be implemented by using code from within its own low-level module. The high-level module does not depend on the low-level module, since it only uses the low-level functionality indirectly through the adapter interface by invoking polymorphic methods to the interface which are implemented by the adapted implementation and its low-level module.[citation needed]

Various patterns such as Plugin, Service Locator,[3] or Dependency injection[4][5] are employed to facilitate the run-time provisioning of the chosen low-level component implementation to the high-level component.[citation needed]

History

[edit]

The dependency inversion principle was postulated by Robert C. Martin and described in several publications including the paper Object Oriented Design Quality Metrics: an analysis of dependencies,[6] an article appearing in the C++ Report in June 1996 entitled The Dependency Inversion Principle,[7] and the books Agile Software Development, Principles, Patterns, and Practices,[1] and Agile Principles, Patterns, and Practices in C#.

See also

[edit]

References

[edit]
  1. ^ a b c d e f Martin, Robert C. (2003). Agile Software Development, Principles, Patterns, and Practices. Prentice Hall. pp. 127–131. ISBN 978-0135974445.
  2. ^ Freeman, Eric; Freeman, Elisabeth; Kathy, Sierra; Bert, Bates (2004). Hendrickson, Mike; Loukides, Mike (eds.). Head First Design Patterns (paperback). Vol. 1. O'REILLY. ISBN 978-0-596-00712-6. Retrieved 2025-08-07.
  3. ^ Aung, Nay Lin (2025-08-07). "Service Locator vs Dependency Injection". Medium. Retrieved 2025-08-07.
  4. ^ Mathews, Sasha (2025-08-07). "You are Simply Injecting a Dependency, Thinking that You are Following the Dependency Inversion…". Medium. Retrieved 2025-08-07.
  5. ^ Erez, Guy (2025-08-07). "Dependency Inversion vs. Dependency Injection". Medium. Retrieved 2025-08-07.
  6. ^ Martin, Robert C. (October 1994). "Object Oriented Design Quality Metrics: An analysis of dependencies" (PDF). Retrieved 2025-08-07.
  7. ^ Martin, Robert C. (June 1996). "The Dependency Inversion Principle" (PDF). C++ Report. Vol. 8, no. 6. pp. 61–66. ISSN 1040-6042. Archived from the original (PDF) on 2025-08-07.
[edit]
感冒挂什么科室 pdi是什么 宫颈液基细胞学检查是什么 什么一笑 放下执念是什么意思
高血糖吃什么食物好 什么洗面奶最好用排行第一 天鹅吃什么 咳嗽属于什么科室 大力念什么
电音是什么意思 宫刑是什么意思 六一送女孩子什么礼物 吃什么水果去火 hipanda是什么牌子
姜水什么时候喝最好 狼狈是什么动物 太监是什么意思 湿气严重吃什么药好得快 总胆固醇高忌口什么
老人吃饭老是噎着是什么原因hcv8jop8ns1r.cn 男人肾虚吃什么最补gysmod.com 918是什么日子hcv8jop5ns0r.cn 骨痂是什么意思hcv8jop8ns8r.cn 输卵管堵塞有什么样症状hcv9jop3ns2r.cn
煮虾放什么hcv9jop2ns6r.cn 骨龄大于年龄意味着什么hcv8jop4ns6r.cn 青色是什么样的颜色hcv9jop6ns6r.cn 有结石不能吃什么东西hcv9jop1ns1r.cn 带状疱疹什么引起的xinjiangjialails.com
尿等待是什么原因hcv8jop1ns6r.cn 肾虚是什么原因引起的cl108k.com 彩超挂什么科hcv9jop3ns9r.cn 极端是什么意思hlguo.com 夹心饼干是什么意思hcv9jop6ns9r.cn
左腰疼是什么原因sscsqa.com 温开水冲服是什么意思ff14chat.com 什么牌子的护肝药最好hcv7jop4ns5r.cn 扁桃体发炎吃什么药好hcv8jop1ns3r.cn 清醒的反义词是什么hcv9jop4ns5r.cn
百度