<small id='ZeP3g'></small><noframes id='ZeP3g'>

<i id='ZeP3g'><tr id='ZeP3g'><dt id='ZeP3g'><q id='ZeP3g'><span id='ZeP3g'><b id='ZeP3g'><form id='ZeP3g'><ins id='ZeP3g'></ins><ul id='ZeP3g'></ul><sub id='ZeP3g'></sub></form><legend id='ZeP3g'></legend><bdo id='ZeP3g'><pre id='ZeP3g'><center id='ZeP3g'></center></pre></bdo></b><th id='ZeP3g'></th></span></q></dt></tr></i><div id='ZeP3g'><tfoot id='ZeP3g'></tfoot><dl id='ZeP3g'><fieldset id='ZeP3g'></fieldset></dl></div>

    1. <legend id='ZeP3g'><style id='ZeP3g'><dir id='ZeP3g'><q id='ZeP3g'></q></dir></style></legend>
    2. <tfoot id='ZeP3g'></tfoot>
      • <bdo id='ZeP3g'></bdo><ul id='ZeP3g'></ul>
    3. 依赖和组合之间的区别?

      Difference between dependency and composition?(依赖和组合之间的区别?)

        <legend id='AZzT7'><style id='AZzT7'><dir id='AZzT7'><q id='AZzT7'></q></dir></style></legend>
        <tfoot id='AZzT7'></tfoot>

                <tbody id='AZzT7'></tbody>

              <small id='AZzT7'></small><noframes id='AZzT7'>

            1. <i id='AZzT7'><tr id='AZzT7'><dt id='AZzT7'><q id='AZzT7'><span id='AZzT7'><b id='AZzT7'><form id='AZzT7'><ins id='AZzT7'></ins><ul id='AZzT7'></ul><sub id='AZzT7'></sub></form><legend id='AZzT7'></legend><bdo id='AZzT7'><pre id='AZzT7'><center id='AZzT7'></center></pre></bdo></b><th id='AZzT7'></th></span></q></dt></tr></i><div id='AZzT7'><tfoot id='AZzT7'></tfoot><dl id='AZzT7'><fieldset id='AZzT7'></fieldset></dl></div>
                <bdo id='AZzT7'></bdo><ul id='AZzT7'></ul>
                本文介绍了依赖和组合之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                此处的定义

                依赖

                一个类的结构或行为的变化会影响其他相关的类,那么这两个类之间存在依赖关系.它需要不一样,反之亦然.当一个类包含另一个类时发生这种情况.

                Change in structure or behaviour of a class affects the other related class, then there is a dependency between those two classes. It need not be the same vice-versa. When one class contains the other class it this happens.

                作曲

                组合是聚合的一种特殊情况.在更具体的方式,受限聚合称为组合.当一个物体包含另一个对象,如果包含的对象不存在不存在容器对象,则称为作文.

                Composition is a special case of aggregation. In a more specific manner, a restricted aggregation is called composition. When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition.

                此处 和 这里

                依赖

                class Employee {
                    private Address address;
                
                    // constructor 
                    public Employee( Address newAddress ) {
                        this.address = newAddress;
                    }
                
                    public Address getAddress() {
                    return this.address;
                    }
                    public void setAddress( Address newAddress ) {
                        this.address = newAddress;
                    }
                }
                

                作曲

                final class Car {
                
                  private final Engine engine;
                
                  Car(EngineSpecs specs) {
                    engine = new Engine(specs);
                  }
                
                  void move() {
                    engine.work();
                  }
                }
                

                推荐答案

                可以看出两个构造函数的区别:

                The difference can be seen in the two constructors:

                • 依赖:Address对象来自外部,它被分配到别的地方.这意味着 AddressEmployee 对象是分开存在的,并且只是相互依赖.

                • Dependency: The Address object comes from outside, it's allocated somewhere else. This means that the Address and Employee objects exists separately, and only depend on each other.

                Composition:在这里您可以看到在inside Car 中创建了一个新的Engine.Engine 对象是 Car 的一部分.这意味着 CarEngine组成.

                Composition: Here you see that a new Engine is created inside Car. The Engine object is part of the Car. This means that a Car is composed of an Engine.

                这篇关于依赖和组合之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Maven JAVA_HOME environment variable is not defined correctly, but it is(Maven JAVA_HOME 环境变量未正确定义,但它是)
                Java System Environment Variable(Java 系统环境变量)
                Java -classpath option(Java -classpath 选项)
                Read environment variable in SpringBoot(在 SpringBoot 中读取环境变量)
                Tomcat 8 - context.xml use Environment Variable in Datasource(Tomcat 8 - context.xml 在数据源中使用环境变量)
                Issue with JAVA_HOME(JAVA_HOME 的问题)
                  <tbody id='VBiCe'></tbody>
                1. <i id='VBiCe'><tr id='VBiCe'><dt id='VBiCe'><q id='VBiCe'><span id='VBiCe'><b id='VBiCe'><form id='VBiCe'><ins id='VBiCe'></ins><ul id='VBiCe'></ul><sub id='VBiCe'></sub></form><legend id='VBiCe'></legend><bdo id='VBiCe'><pre id='VBiCe'><center id='VBiCe'></center></pre></bdo></b><th id='VBiCe'></th></span></q></dt></tr></i><div id='VBiCe'><tfoot id='VBiCe'></tfoot><dl id='VBiCe'><fieldset id='VBiCe'></fieldset></dl></div>

                    <tfoot id='VBiCe'></tfoot>

                      • <legend id='VBiCe'><style id='VBiCe'><dir id='VBiCe'><q id='VBiCe'></q></dir></style></legend>

                        <small id='VBiCe'></small><noframes id='VBiCe'>

                          <bdo id='VBiCe'></bdo><ul id='VBiCe'></ul>