Questions tagged [subclassing]

17 questions
48
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
  • 723
  • 1
  • 6
  • 10
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
  • 943
  • 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
  • 1
  • 1
  • 6
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
  • 3
  • 10
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…
Conrad
  • 288
  • 2
  • 8
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,209
  • 1
  • 10
  • 22
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,565
  • 3
  • 27
  • 45
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
  • 8
  • 15
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…
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…
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
  • 6
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,713
  • 3
  • 14
  • 24
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
0
votes
1 answer

Inheritance or composition for a more advanced implementation of a class?

So i have a class called VirtualMouse, it is used to perform mouse actions such as moving and clicking. public class VirtualMouse { public VirtualMouse() { } public void MoveByOffset(int offsetX, int offsetY) { //…
0
votes
3 answers

Why do the following enum fields extend their base class or base enum?

Regarding enums in java how I understood is Sample enum public enum Strategy { STRATEGY_A { @Override void execute(){ System.out.print("Executing strategy A"); } }, STRATEGY_B { @Override …
Tom Taylor
  • 356
  • 2
  • 4
  • 16
1
2