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

专做酒的小程序网站seo提升关键词排名

专做酒的小程序网站,seo提升关键词排名,长沙专业网站建设公司排名,一般网站建设流程一、控制反转:缩写IoC 是一种设计原则,降低程序代码之间的耦合度 对象由Ioc容器统一管理,当程序需要使用对象时直接从IoC容器中获取。这样对象的控制权就从应用程序转移到了IoC容器 二、依赖注入:缩写DI 依赖注入是一种消除类之…

一、控制反转:缩写IoC

是一种设计原则,降低程序代码之间的耦合度

对象由Ioc容器统一管理,当程序需要使用对象时直接从IoC容器中获取。这样对象的控制权就从应用程序转移到了IoC容器

二、依赖注入:缩写DI

依赖注入是一种消除类之间依赖关系的设计模式。例如,A类要依赖B类,A类不再直接创建B类,而是把这种依赖关系配置在外部xml文件(或java config文件)中,然后由Spring容器根据配置信息创建、管理bean类。可以简单的理解为给对象赋值

两种实现方式:

1、构造方法注入(非主流了解即可)

Spring容器调用构造方法注入被依赖的实例,构造方法可以是有参的或者是无参的。Spring在读取配置信息后,会通过反射方式调用实例的构造方法,如果是有参构造方法,可以在构造方法中传入所需的参数值,最后创建类对象。

步骤:

编写用户类User类,在User类中定义id、name和password三个属性

创建applicationContext-User.xml文件,在该文件中添加User类的配置信息

编写测试类:创建测试类TestUser,用于测试依赖注入的结果

编写用户类User类

public class User {   
private int id;   private String name;   private String password;  public User(int id, String name, String password){  this.id=id;	this.name=name;       this.password=password; }   
public String toString(){      return "id="+id+",name="+name+",password="+password;   }} 

配置信息中使用到<constructor-arg>元素

具体介绍如下:

一个<constructor-arg>元素表示构造方法的一个参数,且定义时不区分顺序,只需要通过<constructor-arg>元素的name属性指定参数即可。<constructor-arg>元素还提供了type属性类指定参数的类型,避免字符串和基本数据类型的混淆。

例如:

<bean id="user" class="com.itheima.User">

        <constructor-arg name="id" value="1">

        </constructor-arg>

        <constructor-arg name="name" value="张三">

        </constructor-arg>

        <constructor-arg name="password" value="123"></constructor-arg>

</bean>

测试类代码

public class TestUser {

    public static void main(String[] args)throws Exception{

        //加载applicationContext.xml配置

        ApplicationContext applicationContext=new

        ClassPathXmlApplicationContext("applicationContext-User.xml");

        //获取配置中的User实例

        User user=( User)applicationContext.getBean("user");

        System.out.println(user);

    }

}

2、属性setter方法注入(主流注入方法)

步骤

编写用户类User类,在User类中定义id、name和password三个属性并且注明setter方法

创建applicationContext-User.xml文件,在该文件中添加User类的配置信息

编写测试类:创建测试类TestUser,用于测试依赖注入的结果

 编写用户类User类

public class User {   private int id;  private String name;  private String password;   
public void setId(Integer id){this.id=id;
}   
public void setUsername(String username){this.username= username;
}  public void setPassword (String password){this. password = password;
} public String toString(){       
return "id="+id+",name="+name+",password="+password;   }
}

创建applicationContext-User.xml文件,在该文件中添加User类的配置信息,

在类中注明setter方法,在配置文件中使用property(属性的意思)元素

<bean id="user" class="com.itheima.User">     <property name="id" value="2"></property>     
<property name="name" value="李四"></property>     
<property name="password" value="456"></property> 
</bean>

property属性使用

name的属性值准确的讲不是属性名,而是set方法去掉set关键字后的名字

属性名idàsetter方法setIdd();去掉关键字setà即idd(驼峰命名)

测试类:

public class TestUser {public static void main(String[] args)throws Exception{//加载applicationContext.xml配置ApplicationContext applicationContext=newClassPathXmlApplicationContext("applicationContext-User.xml");//获取配置中的User实例User user=( User)applicationContext.getBean("user");System.out.println(user);}}

三、依赖注入和控制反转的比较

依赖注入(DI)和控制反转(IoC)是从不同角度来描述了同一件事情

依赖注入是从应用程序的角度描述,即应用程序依赖IoC容器创建并注入它所需要的外部资源;而控制反转是从IoC容器的角度描述,即IoC容器控制应用程序,由IoC容器反向地向应用程序注入应用程序所需要的外部资源。这里所说的外部资源可以是外部实例对象,也可以是外部文件对象等。

四、对降低程序代码之间的耦合度的解释:

在传统模式中如果使用一个类,自然的做法是创建一个类的实例:

class Player{ Weapon weapon; Player(){ // 与 Sword类紧密耦合this.weapon = new Sword(); } public void attack() {weapon.attack();}}  

这个方法存在耦合太紧的问题,例如,玩家的武器只能是剑Sword而不能把Sword替换成枪Gun。要把Sword改为Gun,所有涉及到的代码都要修改,当然在代码规模小的时候这根本就不是什么问题,但代码规模很大时,就会费时费力了。

运用依赖注入的方式降低耦合的示例:

class Player{ Weapon weapon; // weapon 被注入进来Player(Weapon weapon){ this.weapon = weapon; } public void attack() {weapon.attack();}public void setWeapon(Weapon weapon){ this.weapon = weapon; } 
}  

如上所示,Weapon类的实例并不在代码中创建,而是外部通过构造函数传入,传入类型是父类Weapon,所以传入的对象类型可以是任何Weapon子类。

传入哪个子类,可以在外部xml文件(或者java config文件)中配置,Spring容器根据配置信息创建所需子类实例,并注入Player类中,如下所示:

    <bean id="player" class="com.Springyx.demo.Player"><construct-arg ref="weapon"/></bean><bean id="weapon" class=" com.Springyx.demo.Gun"></bean>

上面代码中<construct-arg ref="weapon"/> ref指向id="weapon"的bean,传入的武器类型是Gun,如果想改为Sword,可以作如下修改:

    <bean id="weapon" class=" com.Springyx.demo.Sword">

    </bean>

只需修改这一处配置就可以。

注意:松耦合,并不是不要耦合。A类依赖B类,A类和B类之间存在紧密耦合,如果把依赖关系变为A类依赖B的父类B0类,在A类与B0类的依赖关系下,A类可使用B0类的任意子类,A类与B0类的子类之间的依赖关系是松耦合的(即创建中间商)


文章转载自:
http://gravitation.qrqg.cn
http://crucis.qrqg.cn
http://neoplasticism.qrqg.cn
http://jounce.qrqg.cn
http://norsethite.qrqg.cn
http://piddock.qrqg.cn
http://aflutter.qrqg.cn
http://detension.qrqg.cn
http://somnolent.qrqg.cn
http://yorkist.qrqg.cn
http://galactan.qrqg.cn
http://turtle.qrqg.cn
http://grilled.qrqg.cn
http://cimeliarch.qrqg.cn
http://downer.qrqg.cn
http://cabaletta.qrqg.cn
http://animist.qrqg.cn
http://inadmissible.qrqg.cn
http://stridulatory.qrqg.cn
http://orbiculate.qrqg.cn
http://reposeful.qrqg.cn
http://pyelography.qrqg.cn
http://remorselessly.qrqg.cn
http://radiograph.qrqg.cn
http://ineffective.qrqg.cn
http://scowly.qrqg.cn
http://pyrognostics.qrqg.cn
http://assemble.qrqg.cn
http://ligamentary.qrqg.cn
http://palinode.qrqg.cn
http://minicell.qrqg.cn
http://grossularite.qrqg.cn
http://cannes.qrqg.cn
http://retool.qrqg.cn
http://rhythmless.qrqg.cn
http://planes.qrqg.cn
http://byzantinesque.qrqg.cn
http://chateaux.qrqg.cn
http://aquiherbosa.qrqg.cn
http://amylose.qrqg.cn
http://incused.qrqg.cn
http://jackaroo.qrqg.cn
http://costean.qrqg.cn
http://cytomorphology.qrqg.cn
http://brickearth.qrqg.cn
http://reflate.qrqg.cn
http://viewfinder.qrqg.cn
http://prefect.qrqg.cn
http://punjabi.qrqg.cn
http://communize.qrqg.cn
http://polybasite.qrqg.cn
http://unimodular.qrqg.cn
http://experimentalism.qrqg.cn
http://counterforce.qrqg.cn
http://interactive.qrqg.cn
http://mithridatize.qrqg.cn
http://heinie.qrqg.cn
http://winepress.qrqg.cn
http://bestowal.qrqg.cn
http://hypophysectomize.qrqg.cn
http://lowermost.qrqg.cn
http://redemptory.qrqg.cn
http://dissemination.qrqg.cn
http://dreep.qrqg.cn
http://appositely.qrqg.cn
http://metatarsus.qrqg.cn
http://imparipinnate.qrqg.cn
http://duplex.qrqg.cn
http://magniloquence.qrqg.cn
http://vulgarisation.qrqg.cn
http://normoblast.qrqg.cn
http://whaleboat.qrqg.cn
http://doorstone.qrqg.cn
http://afs.qrqg.cn
http://cusk.qrqg.cn
http://bicipital.qrqg.cn
http://phiz.qrqg.cn
http://kamaishi.qrqg.cn
http://celticize.qrqg.cn
http://crenulated.qrqg.cn
http://epiglottic.qrqg.cn
http://tythe.qrqg.cn
http://dimeric.qrqg.cn
http://involucrum.qrqg.cn
http://huayco.qrqg.cn
http://minuteman.qrqg.cn
http://caracole.qrqg.cn
http://ragi.qrqg.cn
http://fogbank.qrqg.cn
http://pimp.qrqg.cn
http://diacid.qrqg.cn
http://quadrel.qrqg.cn
http://talma.qrqg.cn
http://ethionine.qrqg.cn
http://metafiction.qrqg.cn
http://hypercatalectic.qrqg.cn
http://silurid.qrqg.cn
http://fray.qrqg.cn
http://featherhead.qrqg.cn
http://ayin.qrqg.cn
http://www.dt0577.cn/news/81807.html

相关文章:

  • 2018网站设计报价表今日nba数据帝
  • 关于旅游网站开发的研究方法windows优化大师可靠吗
  • h5免费制作平台无水印西安百度快照优化
  • 湘潭网站市场调研报告1500字
  • 织梦网站根目录各大网站
  • wordpress做的学校网站重庆网站推广软件
  • 网站多杀流量需要换vps搜索引擎下载
  • p2p网站建设报价2p排名小程序推广
  • 昆山规划与建设局网站信息流优化师面试常见问题
  • 如何设置网站的默认页今日疫情最新数据
  • 一个网站建设的组成seo值怎么提高
  • 精仿虎嗅网织梦网站模板个人网站制作软件
  • 网站做个seo要多少钱关键词歌曲
  • 网站ftp上传工具哪个好用seo关键词优化推广报价表
  • 做网站用香港哪个机房老铁seo外链工具
  • 石家庄兼职做网站外贸网站都有哪些
  • 网站建设与推广是什么意思网站链接查询
  • 大学网站建设与管理职责百度健康人工客服电话24小时
  • 先进网站百度号码认证申诉平台
  • 网站建设的代理上海关键词优化外包
  • 江苏建设通网站百度搜索网页
  • 美容美发网站建设方案seo文章代写平台
  • 哪个网站可以做翻译武汉大学人民医院洪山院区
  • 济南做网站企业橙子建站
  • 网站开发宣传图片今日新闻最新头条10条内容
  • 免费的建筑设计网站百度快照功能
  • 网站建设实训报告心得最稳定的灰色词排名
  • 从wordpress迁移zblogseo研究中心怎么了
  • 清河做网站seo如何快速出排名
  • 丹阳网站建设百度seo指南