加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

依赖注入和控制反转

发布时间:2020-12-14 05:23:00 所属栏目:百科 来源:网络整理
导读:2.1?Dependency Injection and Inversion of Control Background " The question is,what aspect of control are [they] inverting? " Martin Fowler posed this question about Inversion of Control (IoC) on his site in 2004. Fowler suggested renaming

2.1?Dependency Injection and Inversion of Control

Java applications?—?a loose term that runs the gamut from constrained applets to n-tier server-side enterprise applications?—?typically consist of objects that collaborate to form the application proper. Thus the objects in an application have?dependencies?on each other.

Although the Java platform provides a wealth of application development functionality,it lacks the means to organize the basic building blocks into a coherent whole,leaving that task to architects and developers. True,you can use design patterns such as?Factory,?Abstract Factory,?Builder,?Decorator,and?Service Locator?to compose the various classes and object instances that make up an application. However,these patterns are simply that: best practices given a name,with a description of what the pattern does,where to apply it,the problems it addresses,and so forth. Patterns are formalized best practices that?you must implement yourself?in your application.

The Spring Framework?Inversion of Control?(IoC) component addresses this concern by providing a formalized means of composing disparate components into a fully working application ready for use. The Spring Framework codifies formalized design patterns as first-class objects that you can integrate into your own application(s). Numerous organizations and institutions use the Spring Framework in this manner to engineer robust,?maintainable?applications.

Java应用程序 - 是一个松松的概念。从Applet小程序到n层的服务器端企业程序,通常由互相写作的对象构成来是程序合适运转。因此,在一个应用程序中的对象有彼此的依赖。

尽管Java平台提供了丰富的应用程序开发功能,但它缺少把基本的建造块组成一个有机整体的手段,而是把这个任务留给了架构师和开发人员。当然,你可以使用设计模式构建应用,比如工厂模式、抽象工厂模式、建造者模式、装饰者模式以及服务器定位模式等等来维护各种各样的类和对象实例。然而,这些模式仅仅是:最佳实践给出的名字,给了模式做什么、到那里应用它、解决什么问题的描述。你必须在你的应用中实现这些。

控制的Spring框架反转(IoC)组件针对这一问题提供了组成不同的组件到一个完全工作的应用程序可以使用的形式化手段。 Spring框架编纂正式的设计模式为可以集成到自己的应用程序(S)第一类对象。许多组织和机构使用Spring框架以这种方式来设计健壮的,可维护的应用程序。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读