Skip to main content

Questions tagged [subclassing]

0 votes
2 answers
298 views

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 ...
CPlus's user avatar
  • 1,219
-1 votes
1 answer
1k views

Subclasses with same behaviour but different attributes for different inputs

Say I have two object types of the same interface MyObj (I am using python in this project so I will use the same for the explanation) class Foo(MyObj): a = [5, 10] class Bar(MyObj): a = [[1, ...
doca's user avatar
  • 255
6 votes
4 answers
4k views

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 ...
Brie's user avatar
  • 288
2 votes
2 answers
798 views

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 ...
Anon's user avatar
  • 3,649
1 vote
2 answers
124 views

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 ...
Michael Stadler's user avatar
0 votes
2 answers
711 views

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 ...
Akinn's user avatar
  • 109
1 vote
3 answers
1k views

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 ...
KGlasier's user avatar
  • 219
0 votes
1 answer
93 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 ...
Joao Vitor's user avatar
2 votes
2 answers
145 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, ...
zuiqo's user avatar
  • 927
54 votes
3 answers
19k views

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 ...
tel's user avatar
  • 569
0 votes
3 answers
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"); ...
Tom Taylor's user avatar
0 votes
1 answer
83 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 | | | |...
kenorb's user avatar
  • 137
7 votes
4 answers
429 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 "...
Dioxin's user avatar
  • 953
2 votes
2 answers
693 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 a ...
vaheeds's user avatar
  • 73
4 votes
2 answers
552 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 ...
1.21 gigawatts's user avatar

15 30 50 per page