我不理解好莱坞原则。

huangapple go评论75阅读模式
英文:

I don't understand the Hollywood Principle

问题

抱歉我的英文表达。

当我阅读《Head First Design Patterns》一书时,我偶然发现了这个原则。我看到其他人在StackOverFlow上问相同的问题,还有一些文章,但我仍然不明白它。

有人能用最简单的术语解释一下吗?

我读过的大多数示例都假设读者已经在使用像Spring这样支持IoC的框架。因为我还是一个初学者,我从未使用过这些框架。

谢谢。

英文:

sorry for my English.

I stumble upon this principle when reading the "Head First Design Patterns" book. I see other peoples ask on StackOverFlow the same question and a few articles but I still don't understand it.

Can someone explain it in the simplest term for me?

Most of the example I've read is assuming that the reader already uses a framework supporting IoC like Spring. I never use those frameworks before because I'm still a beginner.

Thank you.

答案1

得分: 4

这已经有一段时间了,但由于观众的数量,我来解释一下。

好莱坞原则,有时也称为控制反转,它说:“不要给我们打电话,我们会找你”,在软件工程方面,它表明一个依赖于另一个对象的对象不应该调用它,而应该等待另一个对象调用它。

这个原则以更抽象的方式定义了IOC。如您所知,IOC定义了依赖关系的反转。首先,您应该有一个控制中心负责控制依赖项,即创建它们的实例。然后,这个控制中心反转了创建类实例的流程。所以当您想在ClassB中使用ClassA时,您不会创建ClassB的实例然后调用ClassA。您会创建ClassA的实例,然后使用不同的技术将其传递给ClassB并使用它。

要了解更多关于IOC的信息,可以在互联网上进行一些调查,因为我刚刚解释了一些基本概念。

英文:

It's been a while but due to the number of viewers, i explain it.

The Hollywood Principle which sometimes referred to as Inversion of Control says "Don't call us, we'll call you" Which in terms of software engineering it states that an object which depends on another one should not call it but should wait for the other to call it.

This principle defines the IOC with more abstraction. As you know IoC defines inversing the control of dependencies. So first of all you should have a control center responsible for controlling dependencies i.e for making instance of them. This control center then inverses the flow of making instance of classes. So when you want to use ClassA in ClassB, you won't create instance of ClassB then Call ClassA. You make instance of ClassA and pass it to ClassB using different techniques and use it.

For more information about IoC have some invest on the internet as i just explained some basic concepts.

答案2

得分: 0

我会看一下“库与框架”模糊问题。这是在谷歌搜索中找到的一篇文章:库与框架的区别

简而言之: 是由我们的程序调用的(所以我们我们需要它时调用库);框架需要时调用我们的程序片段。

英文:

I would have a look at the "library vs framework" ambiguity problem. Here's one of the article found in Google search: The Difference Between a Framework and a Library.

In short: A library is called by our program (so we call the library when we need it); a framework calls our program's fragments when it needs this.

huangapple
  • 本文由 发表于 2020年10月13日 19:00:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/64333953.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定