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

标签 oop class language-agnostic

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

各种语言的示例会很有帮助...除了 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/

相关文章:

Javascript OOP 帮助/建议/解释

oop - 是否存在确定方法或字段是否属于类的启发式方法?

c++ - 声明指向 *this* 对象的指针的优点或原因是什么?

javascript - 向所有 Angular 模型添加子类

algorithm - 短路前缀 bool 表达式

尚未设置值的 JavaScript 原型(prototype)属性

class - 访问不同类中的变量 - Swift

java - 扩展实现另一个类的抽象类

language-agnostic - 识别不同语言并将它们发送到相应编译器的编译器。可能的?

language-agnostic - 你如何干净地将向后兼容的代码与主代码分开?