Object-InsideOut - a subclass doesn't have much control over the initialization of its superclass

Posted on Thu Jan 12 23:35:07 2006 by earl
a subclass doesn't have much control over the initialization of its superclass

The following example is C++inheritance, where the subclass controls how the superclass is initialized. Sometimes you want to say A is-a B, but you don't want to initialize B in the general fashion. For example, you may want to have new default parameters for the attributes of B.

Is there an elegant way to do this, while using the inside-out paradigm? Here, a subclass doesn't have much control over the initialization of its superclass.

IMHO, the best solution is to turn the is-a relation into a has-a relation. But, that's not what you really want.

class Point { private double x, y; Point (double x, double y) { this.x = x; this.y = y; } double getX () { return x; } double getY () { return y; } } class Circle extends Point { private double radius; Circle (double x, double y, double radius) { super (x, y); // Call Point (double x, double y). this.radius = radius; } double getRadius () { return radius; } }
Direct Responses: 1625 | Write a response