zoukankan      html  css  js  c++  java
  • Ⅷ.spring的点点滴滴--抽象对象和子对象

    承接上文

    抽象对象和子对象


    .net篇(环境为vs2012+Spring.Core.dll v1.31

        public class parent    {
            public string Name { get; set; }
            public int Age { get;set; }
        }
        public class chlid    {
            public string Name { get; set; }
            public int Age { get; set; }
        }
      <object id="p" type="SpringBase.parent,SpringBase">
        <property name="Name" value="cnljli-p0" />  
        <property name="Age" value="1" />
      </object>
      <object id="c" parent="p"  type="SpringBase.chlid,SpringBase">
        <property name="Age" value="2" />
      </object>
      <object id="p1">
        <property name="Name" value="cnljli-p1" />
        <property name="Age" value="2" />
      </object>
      <object id="c1" parent="p1"  type="SpringBase.chlid,SpringBase">
         <property name="Age" value="3" />
      </object>
      <object id="p2"  type="SpringBase.chlid,SpringBase" abstract="true">
        <property name="Name" value="cnljli-p2" />
        <property name="Age" value="3" />
      </object>
      <object id="c2" parent="p2"  type="SpringBase.chlid,SpringBase">
         <property name="Age" value="4" />
      </object>
    1. 可以在不声明一个类的情况下直接写一个Object来做模板

    java篇(环境为Maven+Jdk1.7+IntelliJ IDEA 12.1.4

    package springdemo;
    public class Parent {
        private String name;
        private Integer age;
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Integer getAge() {
            return age;
        }
        public void setAge(Integer age) {
            this.age = age;
        }
    }
    class  Chlid{
        private String name;
        private Integer age;
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Integer getAge() {
            return age;
        }
        public void setAge(Integer age) {
            this.age = age;
        }
    }
        <bean id="p" class="springdemo.Parent">
            <property name="name" value="cnljli-p0" />
            <property name="age" value="1" />
        </bean>
        <bean id="c" parent="p"  class="springdemo.Chlid">
            <property name="age" value="2" />
        </bean>
        <bean id="p1"  class="springdemo.Parent" abstract="true">
            <property name="name" value="cnljli-p2" />
            <property name="age" value="3" />
        </bean>
        <bean id="c1" parent="p1"  class="springdemo.Chlid">
            <property name="age" value="4" />
        </bean>

    javaCsharp的共同点

    1. 用其他类做父类,子类不一定继承父类,但是必须要包含父类的属性
    2. 可以用自己本身做为模板,当设置参数abstract为true的时候这个对象通过id调用的 时候返回会报错
    3. 子类会覆盖父类中某些属性的方法,不过不会覆盖属性为 depends-on(依赖)、dependency-check(依赖检查)、autowire(自动装配模式)、 singleton(单例)和lazy-init(延迟加载)

  • 相关阅读:
    如何写UCHOME移动接口
    无限分类数据树形格式化
    linux下安装eclipse
    python编辑器对比和推荐
    黑马程序员面向对象07天6 (final)
    黑马程序员面向对象07天4 (super,this)
    黑马程序员面向对象07天8 (模版方法)
    黑马程序员面向对象07天7 (接口Interface)
    黑马程序员面向对象08天2 (多态)
    黑马程序员面向对象07天2 (抽象类测试)
  • 原文地址:https://www.cnblogs.com/cnlj/p/3471430.html
Copyright © 2011-2022 走看看