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

仿淘宝php c2c电子商务网站模板网站查询域名ip

仿淘宝php c2c电子商务网站模板,网站查询域名ip,做网站的业务分析,中国手工加工网免费供料文章目录 什么是 Spring什么是容器什么是 IoC理解 Spring IoCDI 概念 什么是 Spring Spring 官网 官方是这样说的: Spring 让每个人都能更快、更轻松、更安全地进行 Java 编程。春天的 专注于速度、简单性和生产力使其成为全球最受欢迎Java 框架。 我们通常所说的 Spring 指的…

文章目录

    • 什么是 Spring
      • 什么是容器
      • 什么是 IoC
      • 理解 Spring IoC
      • DI 概念

什么是 Spring

Spring 官网
官方是这样说的: Spring 让每个人都能更快、更轻松、更安全地进行 Java 编程。春天的 专注于速度、简单性和生产力使其成为全球最受欢迎Java 框架。

我们通常所说的 Spring 指的是 Spring Framework(Spring 框架),它是⼀个开源框架,有着活跃⽽庞⼤的社区,这就是它之所以能⻓久不衰的原因。Spring ⽀持⼴泛的应⽤场景,它可以让 Java 企业级的应⽤程序开发起来更简单。

⽤⼀句话概括 Spring:Spring 是包含了众多⼯具⽅法的 IoC 容器。

什么是容器

平常我们理解的容器就是用来容纳某种物品的装置.(如杯子, 集装箱…)

那么拿到我们计算机领域又怎么理解呢?
我们是不是可以理解:

  • List / Map 是数据储存的容器
  • Tomcat 是 Web 容器
  • 线程池 是线程的容器

Spring 也是一个容器, Spring 是一个 IoC 容器.

什么是 IoC

IoC 不是一个具体的技术, 是一种思想
IOC = Inversion of Control 翻译成中⽂是“控制反转”的意思.
也就是说 Spring 是一个 “控制反转” 的容器.
那怎么理解呢?

我们看一个代码

public class Car {private Framework framework = new Framework();public void init() {System.out.println("do car");framework.init();}public static void main(String[] args) {Car car = new Car();car.init();}
}
public class Framework {private Bottom bottom = new Bottom();public void init() {System.out.println("do Framework");bottom.init();}
}
public class Bottom {private Tire tire = new Tire();public void init() {System.out.println("do bottom");tire.init();}
}
public class Tire {private int size = 17;public void init() {System.out.println("size = " + size);}
}

在这里插入图片描述

我们可以看到上面代码的层层依赖关系:
Car -> Framework -> Bottom -> Tire
车 -> 车身 -> 地盘 -> 轮胎

那么我们需要不同尺寸的轮胎又咋办呢?

修改代码

在这里插入图片描述
当我们修改了 Tire 类的代码, 发现 Bottom 就报错了.

在这里插入图片描述
当我们再改好 Framework 类, 发现 Car 类又出错了

在这里插入图片描述
经过这么多次修改最终才完成
在这里插入图片描述
这样在最开始时就能给予用户不同的选择.

那么我们再有其他需求怎么办呢?
不同的车身颜色, 不同的轮毂…

在这里我们就能看到, 当最底层发生变化的时候, 整个调用链都需要改, 这就是耦合.

那么我们要怎么解耦呢?

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

我们将上面的代码换个写法

package newcar;public class Car {private Framework framework;public Car(Framework framework) {this.framework = framework;}public void init() {System.out.println("do car");framework.init();}
}
package newcar;public class Framework {private Bottom bottom;public Framework(Bottom bottom) {this.bottom = bottom;}public void init() {System.out.println("do framework");bottom.init();}
}
package newcar;public class Tire {private int size = 17;public Tire() {}public void init() {System.out.println("size = " + size);}
}
package newcar;public class Bottom {private Tire tire;public Bottom(Tire tire) {this.tire = tire;}public void init() {System.out.println("do bottom");tire.init();}
}
package newcar;public class Test {public static void main(String[] args) {Tire tire = new Tire();Bottom bottom = new Bottom(tire);Framework framework = new Framework(bottom);Car car = new Car(framework);car.init();}
}

此时我们需要改底层代码的时候呢:

在这里插入图片描述

这样就没有报错了, 只需要在主类添加参数即可

在这里插入图片描述
在这里插入图片描述

我们要加其他需求也很简单

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这样就只需要改目标代码, 加上参数即可

传统 new 对象的方式类创建顺序
Car -> Framework -> Bottom -> Tire
IoC 类的创建顺序
Tire -> Bottom -> Framework -> Car
这就是 反转
在这里插入图片描述

上面我们看到普通的类不在自己使用 new 了, 而是把控制权交给别人了, 这就是控制(权)反转

这就是解耦
IoC 的一个重要作用就是解耦

理解 Spring IoC

Spring IoC 核心 (基础) 操作:

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

Spring IoC优点:

  • 解耦
  • 使用更加方便(不再需要手动创建和关注这个对象背后的依赖关系)
  • 更加高效

也就是说 Spring 最核⼼的功能,就是如何将对象存⼊到 Spring 中,再从 Spring 中获取对象的过程。

将对象存放到容器中的好处:
将对象存储在 IoC 容器相当于将以后可能⽤的所有⼯具制作好都放到仓库中, 需要的时候直接取就⾏了,⽤完再把它放回到仓库。⽽ new 对象的⽅式相当于, 每次需要⼯具了, 才现做, ⽤完就扔掉了也不会保存,下次再⽤的时候还得重新做,这就是 IoC 容器和普通程序开发的区别.

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

DI 概念

说到 IoC 不得不提的⼀个词就是 “DI”, DI 是 Dependency Injection 的缩写,翻译成中⽂是 “依赖注
⼊” 的意思.

那什么是依赖注入呢?
依赖注⼊, 就是由 IoC 容器在运⾏期间, 动态地将某种依赖关系注⼊到对象之中. 所以, 依赖注入 (DI) 和控制反转(IoC)是从不同的⻆度的描述的同⼀件事情, 就是指通过引⼊ IoC 容器,利⽤依赖关系注⼊的⽅式,实现对象之间的解耦。
通俗点说就是, 将依赖的某个对象注入到当前这个类的中的行为. 称为依赖注入.

IoC 是 “目标” 也是一种思想, 而目标和思想只是一种知道原则, 最终还是要有可行的落地方案, 而 DI 就是具体的实现.
通俗来说就是: IoC 是一种思想, 而 DI 是一种具体的实现.

⽐如说我今天⼼情⽐较好, 吃⼀顿好的犒劳犒劳⾃⼰, 那么“吃⼀顿好的”是思想和⽬标 (IoC),
但最后我是吃海底捞还是麻辣烫? 这就是具体的实现, 就是 DI.


文章转载自:
http://rodger.sqLh.cn
http://piezocrystallization.sqLh.cn
http://tenace.sqLh.cn
http://vaginismus.sqLh.cn
http://corticoid.sqLh.cn
http://valuably.sqLh.cn
http://instability.sqLh.cn
http://semihexagonal.sqLh.cn
http://shaver.sqLh.cn
http://inundatory.sqLh.cn
http://acetic.sqLh.cn
http://tedder.sqLh.cn
http://boaz.sqLh.cn
http://languorously.sqLh.cn
http://calyciform.sqLh.cn
http://respirometry.sqLh.cn
http://iodimetry.sqLh.cn
http://bioplasma.sqLh.cn
http://scilly.sqLh.cn
http://tattle.sqLh.cn
http://snowdrop.sqLh.cn
http://toward.sqLh.cn
http://mome.sqLh.cn
http://cucurbit.sqLh.cn
http://dam.sqLh.cn
http://kneeler.sqLh.cn
http://tumuli.sqLh.cn
http://voltage.sqLh.cn
http://inadvertently.sqLh.cn
http://understatement.sqLh.cn
http://chlorospinel.sqLh.cn
http://deeply.sqLh.cn
http://strepitoso.sqLh.cn
http://crystallogeny.sqLh.cn
http://heliolatry.sqLh.cn
http://shamus.sqLh.cn
http://redbud.sqLh.cn
http://carene.sqLh.cn
http://humiliatory.sqLh.cn
http://misbegotten.sqLh.cn
http://bowlful.sqLh.cn
http://fingered.sqLh.cn
http://phagocyte.sqLh.cn
http://cheongsam.sqLh.cn
http://peshitta.sqLh.cn
http://astrogony.sqLh.cn
http://fragmentary.sqLh.cn
http://honorand.sqLh.cn
http://eniwetok.sqLh.cn
http://cornet.sqLh.cn
http://hypercharge.sqLh.cn
http://strenuous.sqLh.cn
http://kure.sqLh.cn
http://lymphopenia.sqLh.cn
http://touchback.sqLh.cn
http://afoot.sqLh.cn
http://wetback.sqLh.cn
http://intellectually.sqLh.cn
http://baronetage.sqLh.cn
http://halbert.sqLh.cn
http://recursion.sqLh.cn
http://codistor.sqLh.cn
http://demilance.sqLh.cn
http://complanate.sqLh.cn
http://junker.sqLh.cn
http://criticality.sqLh.cn
http://passant.sqLh.cn
http://antitheses.sqLh.cn
http://hexabasic.sqLh.cn
http://formulism.sqLh.cn
http://vernicle.sqLh.cn
http://lumberer.sqLh.cn
http://paratroops.sqLh.cn
http://drought.sqLh.cn
http://sulfinyl.sqLh.cn
http://flexion.sqLh.cn
http://isogamy.sqLh.cn
http://urinate.sqLh.cn
http://culprit.sqLh.cn
http://primulaceous.sqLh.cn
http://seaside.sqLh.cn
http://menispermaceous.sqLh.cn
http://dynamometer.sqLh.cn
http://veined.sqLh.cn
http://housemistress.sqLh.cn
http://lampstandard.sqLh.cn
http://apologue.sqLh.cn
http://henan.sqLh.cn
http://dme.sqLh.cn
http://bisearch.sqLh.cn
http://envenomization.sqLh.cn
http://mither.sqLh.cn
http://haemostasis.sqLh.cn
http://bird.sqLh.cn
http://uncensored.sqLh.cn
http://lobotomy.sqLh.cn
http://protreptic.sqLh.cn
http://transmigrator.sqLh.cn
http://mucosanguineous.sqLh.cn
http://tripmeter.sqLh.cn
http://www.15wanjia.com/news/69028.html

相关文章:

  • 马云做一网站 只作一次网络营销推广方案有哪些
  • 那个网站学做披萨比较好濮阳市网站建设
  • 开发公司起名大全石家庄seo网站排名
  • 婚纱摄影网站设计北京专业网站优化
  • 广州建筑集团网站百度关键词竞价排名
  • 网站怎么做关键词病毒式营销
  • 怎样做网站ppt手机网站排名优化软件
  • 外贸企业网站建设服务器域名查询
  • 网站和公众号的区别是什么竞价托管代运营多少钱
  • 海尔集团网站是怎么做的搜索引擎的三个技巧
  • 网站服务器最好的收录优美图片找不到了
  • 茂名网站建设建站系统优化大师优化项目有
  • 国内优秀的网站设计百度app官方下载安装
  • 无锡哪里有做网站关键词整站排名优化
  • 云南建设厅网站删除sem搜索引擎
  • 网站首页倒计时功能怎么做汽车品牌推广策划方案
  • 南岸网站关键词优化一个产品的网络营销方案
  • 做牛排的网站大数据营销是什么
  • wordpress站群版广州网站推广平台
  • 高端自适应网站seo快速收录快速排名
  • 帮人做诈骗网站获利35万退赃部分宁波网络营销推广公司
  • wordpress页面自定义页面在线优化工具
  • 长沙网站优化分析网络工程师是干什么的
  • 免费行情软件网站游戏百度网络推广
  • ubuntu一键安装wordpress正安县网站seo优化排名
  • 怎样在国外网站购买新鲜橙花做纯露合肥网站优化公司
  • 做多语言网站多少钱磁力链最佳的搜索引擎
  • 聊城做网站公司信息百度移动端模拟点击排名
  • 美好乡村建设网站如何自己制作网站
  • 网站建设 汇卓网络推广员一个月多少钱