Tricky compareTo, inheritance, easy to extend – Java
Let’s say we have 4 classes A, B, C, D where: A is a superclass of both B and C and C is a superclass of D. I suppose, in a diagram, it should look like this:
Inheritance and constricted referencing
Let’s say I have BaseA
and BaseB
classes. BaseB
can have to several references of BaseA
instances. Now, we have two other classes, DerivedA
and DerivedB
that respectively inherit from BaseA
and BaseB
.
How do I avoid writing lots of pass-through functions in a wrapper?
I have a class, which wraps another class of a common base type. Because the base type interface is quite large this involves writing a lot of pass-through functions. I am looking for a way to avoid this.
What principle of OOAD is this pattern breaking?
I’m trying to make a case for not putting the structure in the parent BaseModule class I’ve shown below. I’m more for a Strategy Pattern, and minimizing inheritance in favor of has-a relationships, but I am not really sure of what principle of OOAD this pattern is breaking.
Why are constructors not inherited?
I am confused as to what the problems could be if a constructor was inherited from a base class. Cpp Primer Plus says,
Why is the use of constructors discouraged when creating prototypes?
Quick background: In JavaScript, the constructor function for each object type has a prototype
property. The prototype
refers to an object that each constructed object uses as the next step up in its prototype chain. When you want one type to inherent from another type, you can set the prototype
of the child type to a new instance of the parent type.
Why is the use of constructors discouraged when creating prototypes?
Quick background: In JavaScript, the constructor function for each object type has a prototype
property. The prototype
refers to an object that each constructed object uses as the next step up in its prototype chain. When you want one type to inherent from another type, you can set the prototype
of the child type to a new instance of the parent type.
Initializing derived classes in the same way
I have a class Base that has several children, say A, B, C. For testing purposes I’d like to mock those derived classes by deriving from them. So MockA derives from A, MockB derives from B and so on.
Is there a specific name for the “Square inherits from Rectangle” paradox?
A certain failure of OOP is shown with a class Square inheriting from Rectangle, where logically Square is a specialization of Rectangle and should therefore inherit from it, but everything falls apart when you attempt to change a Square’s length or width.
Is there a specific name for the “Square inherits from Rectangle” paradox?
A certain failure of OOP is shown with a class Square inheriting from Rectangle, where logically Square is a specialization of Rectangle and should therefore inherit from it, but everything falls apart when you attempt to change a Square’s length or width.