gpt4 book ai didi

oop - 什么是堕落类(Class)?

转载 作者:行者123 更新时间:2023-12-01 19:25:16 24 4
gpt4 key购买 nike

由于还没人问过,而且我还没有找到合适的答案;简而言之:什么是退化类?

各种语言的示例会很有帮助...除了 UML。 :P

最佳答案

我也在寻找一个明确的答案,这是我迄今为止从谷歌上了解到的:

在数学中,简并性表示极限情况,其中一类对象改变其性质以属于另一个通常更简单的类

  • 当半径接近 0 时,该点是圆的退化情况
  • 当偏心率接近 0 时,圆是椭圆的简并形式

在编程中,遵循“折叠”为更简单的东西的概念,简并性似乎可以通过多种方式使用:

1。没有方法或只有主方法的类:

Big Java:

Finally, you have seen classes with only a main method. Their sole purpose is to start a program. From a design perspective, these are somewhat degenerate examples of classes.

有效的 Java 第二版:

Item 14: In public classes, use accessor methods, not public fields

Occasionally, you may be tempted to write degenerate classes that serve no purpose other than to group instance fields:

// Degenerate classes like this should not be public!
class Point {
public double x;
public double y;
}

2。特异性较低的类,导致其行为类似于另一个更简单的类:

Learning Java:

For example, the class of List and List share the plain old Java class List. List is called the raw type of the generic class. Every generic has a raw type. It is the degenerate, “plain” Java form from which all of the generic type information has been removed and the type variables replaced by a general Java type like Object.

有效的 Java 第二版:

// The worst possible legal hash function - never use!
@Override public int hashCode() { return 42; }

It’s legal because it ensures that equal objects have the same hash code. It’s atrocious because it ensures that every object has the same hash code. Therefore, every object hashes to the same bucket, and hash tables degenerate to linked lists.

3。最简单、最空的类实例:

大 java :

However, sometimes you get into philosophical questions dealing with degenerate inputs: empty strings, shapes with no area, and so on.

关于oop - 什么是堕落类(Class)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6810982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com