Questions tagged [subclassing]
19 questions
54
votes
3 answers
What's the difference between a subclass and a subtype?
The highest rated answer to this question about the Liskov Substitution Principle takes pains to distinguish between the terms subtype and subclass. It also makes the point that some languages conflate the two, whereas others do not.
For the…
tel
- 569
49
votes
6 answers
What would be the disadvantage to defining a class as a subclass of a list of itself?
In a recent project of mine, I defined a class with the following header:
public class Node extends ArrayList {
...
}
However, after discussing with my CS professor, he stated that the class would both be "horrible for memory" and "bad…
Addison Crump
- 741
7
votes
4 answers
Subtyping without adding state or behavior - Bad Practice?
Observation
There are many Exception subtypes that don't have any added state or behavior. For example, ClosedByInterruptException code.
Question
Why is subtyping without adding state or behavior "acceptable" in the case of Exception? From what I…
Dioxin
- 953
- 1
- 9
- 19
7
votes
1 answer
Is calling the superclass constructor in a subclass really important?
The following piece of Python code uses a superclass solely as the repository of functions that one of more subclasses may draw from:
class Class(object):
''' A trivial repository for functions to be inherited '''
def function(self):
…
XavierStuvw
- 181
7
votes
1 answer
Is the complexity needed to prevent downcasting from constructor to overridden method worth it?
Invoking non-final instance methods in constructors risks downcasting from a constructor to an overridden method as such:
public class Start {
public static void main(String[] args) {
try {
ClassB obj = new ClassB();
…
konishiki
- 475
6
votes
4 answers
Which is preferred: subclass double or create extension methods to test (relative) equality due to floating point differences?
I am writing numerical calculation software using .NET C#, which needs to be blazingly fast. There is a lot of fractional math. So using decimal type is pretty much out of the question, given its poor speed relative to using double. But of course…
Brie
- 288
4
votes
2 answers
Would you use object proxy, extend the class, if else conditions or make a duplicate class for supporting two different API's?
This is not an easy one but here goes. I'm working on adapting a JavaScript project (ACE Editor) to support two different targets but maybe more. Any way I look at it, it looks like a large task and no approach feels quite right.
I started to…
1.21 gigawatts
- 1,237
2
votes
2 answers
C++: Achieving a decoupled "Definition is Registration" paradigm for derived classes?
I'm trying to engineer this:
200 subclasses [ Derived Classes ]
After a subclass is defined, I wont need to edit any other file. [ Decoupled ]
Subclass Definition registers itself. [ Definition is Registration ]
What I could do instead:
Create a…
Anon
- 3,639
2
votes
2 answers
Object that can set its own subclass/amend its methods with subclass?
I have a database that stores client data. All data is in one table. For each client, there is one row per day. Clients have different kinds of contracts, their data format remains the same, however, the underlying dynamics are different.
I am…
zuiqo
- 927
2
votes
2 answers
How to change this implementation to cover drawbacks of Mediator Design Pattern here
I am new to design patterns, here is a classic example of basic mediator pattern that has 3 problems with it, first of all take a look at the application image, diagram, code and description:
We use a DialogDirector to implement the font dialog…
vaheeds
- 73
- 8
1
vote
2 answers
Modeling Class hierarchy that may change during runtime
I've been building an application that processes documents through different filters.
I have a class (or better as an interface for creating test-doubles?) called Document. The Document class contains many fields and therefore I was thinking about…
Michael Stadler
- 119
1
vote
3 answers
Classification of methods that are only accessible by a child class and its parent
I'm trying to document some of my JavaScript according to this JavaScript Documentation guide and came across member access (private, public, protected). I was wondering what the classification would be of a member/function that was defined in the…
KGlasier
- 219
1
vote
2 answers
Parameterization vs subclassing
Example taken from : Agile software development : principles, patterns and practices
A new employee is added by the receipt of an AddEmp transaction. This transaction contains the employee's
name, address, and assigned employee number. The…
q126y
- 1,733
0
votes
3 answers
Are there any benefits to delegation over subclassing/inheritance in the case of a singleton?
Example:
The MacOS API known as Cocoa uses Delegation to specify various behaviors within the app. A Delegate is a separate object that implements a set of methods that are called by an original object. For example an NSApplication calls the…
CPlus
- 1,209
0
votes
2 answers
Make a group of classes visible only by a single class
I have a group of classes (let's say B,C,D,E) that basically represent specific operations a user can execute. I would like to have a single point of access for creating these object and launch their executions.
My first idea to accomplish that is…
Akinn
- 109
- 3