开发者

What is a Degenerate Class?

Since no one has asked yet, and I've开发者_开发问答 yet to find a suitable answer; simply put: What is a Degenerate Class?

Examples of various languages would be helpful...Except UML. :P


I'm also looking for a definitive answer, here's how I've understood it so far from google:

In mathematics, degeneracy signifies the limiting case in which a class of object changes its nature so as to belong to another, usually simpler, class.

  • the point is a degenerate case of the circle as the radius approaches 0
  • the circle is a degenerate form of an ellipse as the eccentricity approaches 0

In programming, following this concept of 'collapsing' into something simpler, degeneracy seems to be used in a number of ways:

1. A class with no methods or just a main method:

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.

Effective Java 2nd edition:

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. A class with less specificity that causes it to behave like another simpler class:

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.

Effective Java 2nd edition:

// 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. The simplest, emptiest instance of a class possible:

Big Java:

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


From here I'm guessing that it's a class with no behavior (i.e. no methods).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜