iOS 中的控制反转,框架和静态库有何不同?
How do Framework and Static Library differ for inversion of control in iOS?
在 answers 的一个关于 iOS Framework
vs. Static Library
的问题中,引用了 yoAlex5,
A Library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client.
A Framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points. The main control of the program is inverted, moved away from you to the framework. (Inversion of Control)
任何人都可以用最少的代码片段给出 iOS 的任何示例,以便我可以理解 Static Library
如何不能支持控制反转而 Framework
可以?
在您引用的问题的 accepted answer 中,提到了以下内容:
Hence on iOS, your only option is basically to use a static library or
static framework (the main difference being that a static framework is
distributed as a compiled .a file most often, whereas a static library
may simply be included as a subproject - you can see all of the code -
which is compiled first and its resulting .a file used as a dependency
by the project).
所以 iOS 上的主要区别实际上是框架通常以编译形式使用,而库则用作代码。因此原则上都支持控制反转。
但是,即使框架可以提供的一切,也可以由库提供,我们应该明确地将某些功能限制在框架中。 Wiki says:
Frameworks have key distinguishing features that separate them from
normal libraries:
• inversion of control: In a framework, unlike in
libraries or in standard user applications, the overall program's flow
of control is not dictated by the caller, but by the framework.
• extensibility: A user can extend the framework – usually by
selective overriding – or programmers can add specialized user code to
provide specific functionality.
• non-modifiable framework code: The
framework code, in general, is not supposed to be modified, while
accepting user-implemented extensions. In other words, users can
extend the framework, but cannot modify its code.
在 answers 的一个关于 iOS Framework
vs. Static Library
的问题中,引用了 yoAlex5,
A Library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client.
A Framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points. The main control of the program is inverted, moved away from you to the framework. (Inversion of Control)
任何人都可以用最少的代码片段给出 iOS 的任何示例,以便我可以理解 Static Library
如何不能支持控制反转而 Framework
可以?
在您引用的问题的 accepted answer 中,提到了以下内容:
Hence on iOS, your only option is basically to use a static library or static framework (the main difference being that a static framework is distributed as a compiled .a file most often, whereas a static library may simply be included as a subproject - you can see all of the code - which is compiled first and its resulting .a file used as a dependency by the project).
所以 iOS 上的主要区别实际上是框架通常以编译形式使用,而库则用作代码。因此原则上都支持控制反转。
但是,即使框架可以提供的一切,也可以由库提供,我们应该明确地将某些功能限制在框架中。 Wiki says:
Frameworks have key distinguishing features that separate them from normal libraries:
• inversion of control: In a framework, unlike in libraries or in standard user applications, the overall program's flow of control is not dictated by the caller, but by the framework.• extensibility: A user can extend the framework – usually by selective overriding – or programmers can add specialized user code to provide specific functionality.
• non-modifiable framework code: The framework code, in general, is not supposed to be modified, while accepting user-implemented extensions. In other words, users can extend the framework, but cannot modify its code.