English 中文(简体)
前班和后班是什么?
原标题:What is front-end class and back-end class?
  • 时间:2012-05-15 00:17:30
  •  标签:
  • java

当时,Guys在寻找组成和继承之间的区别时,我发现这个职位有些地方。

根据员额组成情况,在重新使用法典方面比继承更好。

class Fruit {

    // Return int number of pieces of peel that
    // resulted from the peeling activity.
    public int peel() {

        System.out.println("Peeling is appealing.");
        return 1;
    }
}

class Apple {

    private Fruit fruit = new Fruit();

    public int peel() {
        return fruit.peel();
    }
}

class Example2 {

    public static void main(String[] args) {

        Apple apple = new Apple();
        int pieces = apple.peel();
    }
}

改变后级

class Peel {

    private int peelCount;

    public Peel(int peelCount) {
        this.peelCount = peelCount;
    }

    public int getPeelCount() {

        return peelCount;
    }
    //...
}

class Fruit {

    // Return int number of pieces of peel that
    // resulted from the peeling activity.
    public Peel peel() {

        System.out.println("Peeling is appealing.");
        return new Peel(1);
    }
}

// Apple must be changed to accomodate // the change to Fruit

class Apple {

    private Fruit fruit = new Fruit();

    public int peel() {

        Peel peel = fruit.peel();
        return peel.getPeelCount();
    }
}

// This old implementation of Example2 // still works fine.

class Example1 {

    public static void main(String[] args) {

        Apple apple = new Apple();
        int pieces = apple.peel();
    }
}

这是我根据该职位掌握的情况,即,“如果后端班的交接发生变化,上端班的实施也发生变化,但不是接口”。

<>interface, 在这里,?

THIS IS JUST MY ASSUMPTION TELL ME JUST IM IM WRONG?

Is the back-end class the interface because front-end class depends on it?
Is the implementation of front-end class the implementation code inside the front-end class?
Is front-end class also an interface because the code inside Example depends on it?

它们是否由于改为后端界面<>/strong>而有意改为front-end界面? 因此,取决于front-end界面的代码仍然有效。

If I use inheritance instead is subclass tightly coupled in superclass? Because change to superclass will also change to subclass so code that depends on subclass will may not work.

任何遗产都很薄弱。

问题回答

。 然而,这就是而不是上述例子。

“entergraph

以上实例是使用构成,这意味着Fruit >是part ofApple(见uml 。 这完全是反攻! 在此情况下,<代码>Fruit和Apple分别实施石轮。 <peel(> in AppleuseFruit.peel()

“entergraph

我认为,提出的观点是,如果<代码>Apple<>/code>使用与<代码>Fruit的构成关系,则该编码can即独立于水果。 例如,我不使用<代码>Fruit.peel()来计算<代码>Apple.peel(>,我可以使用其他一些执行方法。 但是,如果<代码>Apple从Fruit继承 pe,则在<代码>Fruit上作改动。 因此,<代码>Apple并不独立于<代码>Fruit,因此,我们说,该编码是紧密结合的。

这在两种方式中都是一个坏的事例,即1)我们都知道,“pple”是指“......”成果,因此,继承似乎最正确。 (2) 继承似乎是执行事项的最佳方式,因为使用组成要求你改正。 页: 1

EDIT:读到该文章后,我感到主要问题是概述使用遗产的陷阱。 使用继承权(适当>没有任何错误。 仅仅为了再使用法典,如果孩子的班子真正获得<>/em>从超级班子继承行为,就会造成问题。

www.un.org/spanish/ecosoc 回答问题!

Is the back-end class the interface because front-end class depends on it?

够了。 所有班级都有“校外” 这并不意味着它们实际上在其类别声明中有<条码>执行国际红十字与红新月/代码”,它只是提及物体的shape——无论这些方法如何运作,这些方法是什么。

Is the implementation of front-end class the implementation code inside the front-end class?

大约是。 构成某类方法整体的法典的实际逻辑是该类方法的实施。

Is front-end class also an interface because the code inside Example depends on it?

相当多。 <代码>Apple与任何其他类别一样,具有隐含的接口。 如果Example 采用Apple类别,则只能通过使用作为接口一部分的方法才能这样做。

Are they lousely coupled because change to back-end interface didnt make change to front-end interface?

Yeah, 这是一种使用“双胞胎”这一短语的一种方式。

If I use inheritance instead is subclass tightly coupled in superclass? Because change to superclass will also change to subclass so code that depends on subclass will may not work.

是的。 这两门课是紧加在一起的,因为他们的行为并非完全集中在每个不同班级。 这并不总是错的,取决于局势。

任何遗产都很薄弱。 [原文]

由于行为由上下层和下级分担。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...