抽象不应该依赖于细节.细节应该取决于抽象? [英] Abstractions should not depend upon details. Details should depend upon abstractions?

查看:33
本文介绍了抽象不应该依赖于细节.细节应该取决于抽象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几天里,我已经阅读了很多关于依赖注入/控制反转/依赖反转的内容.我认为,现在我对这个概念的理解要好得多.但我仍然没有从维基百科中得到以下内容:

In past couple of days, I have read about quite a lot about dependency injection/inversion of control/inversion of dependency. I think that, now my understanding of the concept is much better. But I still don't get the following from wikipedia:

A.高级模块不应该依赖于低级模块.两个都应该依赖于抽象.B. 抽象不应该依赖于细节.细节应该依赖于抽象.

A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend upon details. Details should depend upon abstractions.

我理解高级模块的部分不应该依赖于低级模块. 但是,我对抽象和细节感到困惑.有人可以帮我简化它们吗?谢谢.

I understand the part of High-level modules should not depend on low-level modules. But, I am confused about abstractions and details.Can someone please simplify them for me. Thanks.

推荐答案

这意味着如果细节发生变化,它们不应该影响抽象.抽象是客户查看对象的方式.对象内部究竟发生了什么并不重要.让我们以汽车为例,踏板、方向盘和变速杆是发动机内部发生的事情的抽象.但它们并不取决于细节,因为如果有人将我的旧发动机更换为新发动机,我应该仍然能够在不知道发动机改变的情况下驾驶汽车.

It means that if the details change they should not affect the abstraction. The abstraction is the way clients view an object. Exactly what goes on inside the object is not important. Lets take a car for example, the pedals and steering wheel and gear lever are abstractions of what happens inside the engine. They do not depend on the details though because if someone changes my old engine for a new one I should still be able to drive the car without knowing that the engine changed.

另一方面,细节必须符合抽象所说的内容.我不想实现一个突然导致刹车使汽车速度加倍的发动机.我可以以任何我想要的方式重新实施刹车,只要它们在外部表现相同即可.

The details on the other hand MUST conform to what the abstraction says. I would not want to implement an engine that suddenly causes the brakes to double the speed of the car. I can re-implement brakes any way I want as long as externally they behave the same way.

这篇关于抽象不应该依赖于细节.细节应该取决于抽象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆