What is a degenerate class?

Since no one has yet asked, and I have not yet found a suitable answer; just put: What is a degenerate class?

Examples of different languages ​​would be useful ... Except UML .: P

+6
source share
3 answers

From here I assume that this is a class with no behavior (i.e. no methods).

+1
source

I am also looking for the final answer, here is how I understood it so far from google:

In mathematics, degeneration means the limiting case in which the class of an object changes its nature so as to belong to another, usually simpler, class .

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

In programming, following this concept of β€œcollapsing” into something simpler, degeneration is apparently used in several ways:

1. A class without methods or only the main method:

Big Java:

Finally, you saw classes with only the main method. Their only goal is to run the program. In terms of design, these are somewhat degenerate examples of classes.

Effective Java 2nd edition:

Point 14: In public classes, use access methods, not public fields.

Sometimes you may be tempted to write degenerate classes that serve no purpose other than grouping instance fields:

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

2. A class with less specificity, which makes it behave as yet another simpler class:

Learning Java:

For example, the List and List classes use the plain old list of Java classes. The list is called the raw type of the generic class. Each ancestor has a raw type. This is a degenerate "simple" form of Java , from which all information about a common type is removed, and type variables are replaced with a common Java type, such as Object.

Effective Java 2nd edition:

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

Its validity, since it guarantees that equal objects have the same hash code. Its atrocious because it guarantees that every object has the same hash code. Therefore, each object hash for the same bucket and hash table degenerates into linked lists .

3. The simplest, trivial instance of a class:

Big Java:

However, sometimes you get into philosophical questions regarding degenerate inputs: empty lines, figures without a region , etc.

+5
source

objects usually have state (data), behavior (methods) and identifier. an object without data may be a stream. an object without methods can be http://en.wikipedia.org/wiki/Business_object .

0
source

Source: https://habr.com/ru/post/893468/


All Articles