Questions tagged [subclassing]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
72 views

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 ...
2
votes
2answers
115 views

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, ...
0
votes
3answers
2k views

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"); ...
0
votes
1answer
56 views

How to organise tree of sub-classes which should interact?

I'm writing a trading framework in MQL and I'm confused how I should organise my class hierarchy. |-- Terminal (Log) | |-- Market | | |-- Chart | | | |-- Draw | |-- Account | | | |...
7
votes
4answers
372 views

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 "...
2
votes
2answers
372 views

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 ...
4
votes
2answers
134 views

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 ...
48
votes
6answers
6k views

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<Node> { ... } However, after discussing with my CS professor, he stated that ...
3
votes
1answer
10k views

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 ...
7
votes
1answer
258 views

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 ...
1
vote
2answers
216 views

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, ...