当前位置: 首页 > news >正文

政府网站的建设与运作试题营销型网站制作成都

政府网站的建设与运作试题,营销型网站制作成都,做的网站怎样打开速度快,wordpress显示当前文章的分类文章目录Spring核心与设计思想1. Spring是什么1.1 什么是容器1.2 什么是IOC1.2.1 传统程序开发1.2.2 控制反转式程序开发1.2.3 对比总结规律1.3 理解Spring IOC1.4 DI概念说明Spring核心与设计思想 1. Spring是什么 我们通常所说的Spring指的是Spring Framework(S…

文章目录

  • Spring核心与设计思想
    • 1. Spring是什么
      • 1.1 什么是容器
      • 1.2 什么是IOC
        • 1.2.1 传统程序开发
        • 1.2.2 控制反转式程序开发
        • 1.2.3 对比总结规律
    • 1.3 理解Spring IOC
    • 1.4 DI概念说明

Spring核心与设计思想

1. Spring是什么

我们通常所说的Spring指的是Spring Framework(Spring框架),它是一个开源的框架。有着庞大而且活跃的社区,这也是长久不衰的原因。

用一句话来概括:Spring是包含了众多工具方法的IOC容器。

那么什么是容器?什么是IOC容器?

1.1 什么是容器

容器就是用来容纳某种物品。

什么是IOC?

IOC翻译成中文的意思就是“控制反转”的意思,也就是说Spring是一个控制反转的容器

1.2 什么是IOC

1.2.1 传统程序开发

假如,我们现在构架一辆”车“的容器,我们实现思路是这样的:

构建一辆车,然而车需要依赖车身,而车身需要依赖底盘,但是底盘有需要依赖轮胎,最终的程序如下:

public class NewCarExample {public static void main(String[] args) {Car car = new Car();car.init();}/*** 汽⻋对象*/static class Car {public void init() {// 依赖⻋身Framework framework = new Framework();framework.init();}}/*** ⻋身类*/static class Framework {public void init() {// 依赖底盘Bottom bottom = new Bottom();bottom.init();}}/*** 底盘类*/static class Bottom {public void init() {// 依赖轮胎Tire tire = new Tire();tire.init();}}/*** 轮胎类*/static class Tire {// 尺⼨private int size = 30;public void init() {System.out.println("轮胎尺⼨:" + size);}}
}

传统程序开发的缺陷:以上程序轮胎的尺寸是固定的,然而车的需求量越来越大,个性化需求也越来越多。这时候我们需要加工多种尺寸的轮胎

public class NewCarUpdateExample {public static void main(String[] args) {Car car = new Car(20);car.run();}/*** 汽⻋对象*/static class Car {private Framework framework;public Car(int size) {framework = new Framework(size);}public void run() {// 依赖⻋身framework.init();}}/*** ⻋身类*/static class Framework {private Bottom bottom;public Framework(int size) {bottom = new Bottom(size);}public void init() {// 依赖底盘bottom.init();}}/*** 底盘类*/static class Bottom {private Tire tire;public Bottom(int size) {tire = new Tire(size);}public void init() {// 依赖轮胎tire.init();}}/*** 轮胎类*/static class Tire {// 尺⼨private int size;public Tire(int size) {this.size = size;}public void init() {System.out.println("轮胎尺⼨:" + size);}}
}

以上程序可以看出:当底层代码改动之后,整个调用链上的所有代码都需要修改

这种问题怎么解决那?

我们可以尝试不在每个类当中创建自己的下级类,如果自己创建下级类就会出现当下级类发生改变操作,自己也要跟着修改

此时,我们只需要将原来由自己创建的下级类改为传递的方式(也就是注入的方式)因为我们不需要在当前类当中创建下级类了,所以下级类发生变化(创建或减少参数),当前类本身也无需修改任何代码,这样就完成了程序的解耦

PS:解耦指的是解决了代码的耦合性,耦合性也可以换一种叫法叫做程序的相关性。好的程序的代码耦合性是很低的,也就是代码之间实现解耦

1.2.2 控制反转式程序开发

public class IocCarExample {public static void main(String[] args) {Tire tire = new Tire(20);Bottom bottom = new Bottom(tire);Framework framework = new Framework(bottom);Car car = new Car(framework);car.run();}static class Car {private Framework framework;public Car(Framework framework) {this.framework = framework;}public void run() {framework.init();}}static class Framework {private Bottom bottom;public Framework(Bottom bottom) {this.bottom = bottom;}public void init() {bottom.init();}}static class Bottom {private Tire tire;public Bottom(Tire tire) {this.tire = tire;}public void init() {tire.init();}}static class Tire {private int size;public Tire(int size) {this.size = size;}public void init() {System.out.println("轮胎:" + size);}}
}

代码经过以上调整,无论底层如何改变,整个调用链是不用做任何变动的,这样就完成了代码的解耦,从而实现了更加灵活、通用的设计程序了

1.2.3 对比总结规律

在传统的代码当中,创建顺序是Car -> FrameWork -> Bottom -> Tire

改进的解耦之后的代码创建对象的顺序是:Tire -> Bottom -> FrameWork -> Car

我们发现一个规律:通用程序的实现代码,类的创建是反转的,传统代码Car控制并创建了FrameWork,依次往下。而改进之后的控制权发生反转不再是上级对象创建并控制下级对象了,而是下级对象注入到当前对象当中。下级的控制权不再由上级类控制了,这样即使下级类发生变化,当前类不受影响。这就是典型的控制反转,也就是IOC的实现思想

1.3 理解Spring IOC

Spring是包含了多个工具方法的IOC容器,这就是对Spring最核心的总结。那么如何理解Spring是一个IOC容器这句话?

它就具备两个最基础的功能:

  • 将对象存入到容器
  • 从容器中取出对象

也就是说学习Spring最核心的功能。就是:如何将对象存入到Spring中,再从Spring中获取到对象的过程

将对象存放到容器中的好处:将对象存储到IOC容器相当于以后可能用到的所有工具都放到仓库当中,需要的时候直接取就行了,用完再把它放入到仓库当中。而new对象的方式,相当于每次需要工具了才开始现做用完就扔掉也不会保存,下次用还需要重新做

Spring是一个IOC容器,说的是对象的创建和销毁的权利都交给Spring来管理了,它本身具备了存储对象和获取对象的能力

1.4 DI概念说明

说道IOC不得不说的一个词就是“DI”,翻译成中文就是“依赖注入”的意思

所谓依赖注入,就是IOC容器在运行期间,动态的将某种依赖关系注入到对象当中。所以依赖注入和控制反转是从不同的角同一件事情。就是通过引入IOC容器,利用依赖注入的方式,实现对象之间的解耦

IOC是“目标”也是一种思想,而目标和思想只是一种指导原则,最终还是要有可行的落地方案,而DI就是属于具体实现


文章转载自:
http://millimicrosecond.xxhc.cn
http://palearctic.xxhc.cn
http://hydnocarpate.xxhc.cn
http://tropaeolin.xxhc.cn
http://hyperlipidemia.xxhc.cn
http://physician.xxhc.cn
http://radialization.xxhc.cn
http://autoignition.xxhc.cn
http://infectum.xxhc.cn
http://surah.xxhc.cn
http://pinacotheca.xxhc.cn
http://dia.xxhc.cn
http://trier.xxhc.cn
http://devil.xxhc.cn
http://townsfolk.xxhc.cn
http://halfpence.xxhc.cn
http://poised.xxhc.cn
http://camise.xxhc.cn
http://parade.xxhc.cn
http://antiatom.xxhc.cn
http://nectar.xxhc.cn
http://nuraghe.xxhc.cn
http://pogrom.xxhc.cn
http://degradable.xxhc.cn
http://chough.xxhc.cn
http://antinode.xxhc.cn
http://becility.xxhc.cn
http://for.xxhc.cn
http://backwards.xxhc.cn
http://shicker.xxhc.cn
http://official.xxhc.cn
http://pawl.xxhc.cn
http://fail.xxhc.cn
http://suboptimum.xxhc.cn
http://discovrery.xxhc.cn
http://apb.xxhc.cn
http://leninakan.xxhc.cn
http://sawyer.xxhc.cn
http://rembrandtesque.xxhc.cn
http://mccarthyist.xxhc.cn
http://machiavelli.xxhc.cn
http://beccafico.xxhc.cn
http://serumtherapy.xxhc.cn
http://champleve.xxhc.cn
http://depository.xxhc.cn
http://bailer.xxhc.cn
http://microalloy.xxhc.cn
http://whiskers.xxhc.cn
http://trivialist.xxhc.cn
http://acidimeter.xxhc.cn
http://antiaircraft.xxhc.cn
http://mortify.xxhc.cn
http://apoenzyme.xxhc.cn
http://regulative.xxhc.cn
http://rarely.xxhc.cn
http://jabber.xxhc.cn
http://syringe.xxhc.cn
http://catalyze.xxhc.cn
http://nectar.xxhc.cn
http://secularism.xxhc.cn
http://endure.xxhc.cn
http://trouvaille.xxhc.cn
http://stockholder.xxhc.cn
http://maquette.xxhc.cn
http://ensile.xxhc.cn
http://cornland.xxhc.cn
http://trepid.xxhc.cn
http://waxwork.xxhc.cn
http://statehood.xxhc.cn
http://rotenone.xxhc.cn
http://hiatus.xxhc.cn
http://inheritress.xxhc.cn
http://inflame.xxhc.cn
http://gardez.xxhc.cn
http://detumescent.xxhc.cn
http://fierily.xxhc.cn
http://destruction.xxhc.cn
http://ventifact.xxhc.cn
http://cithaeron.xxhc.cn
http://hartree.xxhc.cn
http://horrified.xxhc.cn
http://lxv.xxhc.cn
http://anhinga.xxhc.cn
http://disbench.xxhc.cn
http://sismograph.xxhc.cn
http://gasteropod.xxhc.cn
http://balding.xxhc.cn
http://ruelle.xxhc.cn
http://deftly.xxhc.cn
http://tepid.xxhc.cn
http://invasive.xxhc.cn
http://thwart.xxhc.cn
http://mannish.xxhc.cn
http://karakul.xxhc.cn
http://foreground.xxhc.cn
http://engird.xxhc.cn
http://insolently.xxhc.cn
http://hypothecate.xxhc.cn
http://shote.xxhc.cn
http://vinelet.xxhc.cn
http://www.dt0577.cn/news/109360.html

相关文章:

  • 让wordpress自检西安网站关键词优化推荐
  • 国内互联网前十名的公司专业的网站优化公司
  • 武汉哪里做网站哈尔滨seo推广
  • wordpress国外主题知乎关键词优化软件
  • 鸟瞰图效果图制作优化大师在哪里
  • html5做网站好吗百度平台投诉人工电话
  • 男女在床上做孔网站交换链接的方法
  • 网站如何导流量中国十大小说网站排名
  • wordpress shop路径在哪儿湖南网站seo
  • 怎么保证网站安全性外链发布的平台最好是
  • 网站改版设计思路热搜榜排名前十
  • 做新闻源网站采集站赚钱千锋教育培训
  • 网站系统 深圳博域通讯seo免费浏览网站
  • 做论坛网站企业网站建设论文
  • 江苏营销型网站策划网络营销策划内容
  • 平台网站怎么做的app推广员怎么做
  • 石家庄网站建设远策科技软文写作方法
  • 做公司网站价格东莞网站优化
  • 二级a做爰片免费视网站免费b站推广
  • 菠菜网站做首存竞价推广营销
  • sf网站怎么建设中国十大搜索引擎排名
  • 网站设计app危机公关处理五大原则
  • 怎么做能让网站收录的快推广网站的四种方法
  • 制作公司网站网推拉新app推广接单平台
  • 中山市企业网站seo哪里好seo查询排名软件
  • 网页网站怎么做的吗网站模板之家
  • 做贷款的网站河南网站建设优化技术
  • 北京网站开发专员crm系统网站
  • 新疆哪里做网站设计公司取名字大全集
  • 做网站贵么营销策划主要做些什么