Questions tagged [overriding]
15 questions
32
votes
5 answers
Is overriding concrete methods a code smell?
Is it true that overriding concrete methods is a code smell? Because I think if you need to override concrete methods:
public class A{
public void a(){
}
}
public class B extends A{
@Override
public void a(){
}
}
it can be…

ggrr
- 5,725
- 11
- 35
- 37
5
votes
1 answer
Can I add to a built-in function?
I want be to be able to re-write the code of an existing PHP function in an abstract manner.
Here is an example:
scandir() scans a directory for files and folders, and returns the relative paths '.' and '..' .
While I could just create a new…

Platinum Fire
- 151
- 2
4
votes
4 answers
How name public method that relays to abstract methods of its children (c#)
I've run into the following situation multiple times, and in every case have struggled with the naming.
I want a class to force its children to implement a method, but I want the parent class to be able to override this behaviour if needed. For…

Adam B
- 1,506
- 2
- 12
- 20
4
votes
3 answers
Is Java's @Override annotation still good practice in these modern times?
When the @Override annotation was introduced in Java 1.5, which feels like back in the days when the dinosaurs roamed the Earth, it was a good idea at the time because, amongst other advantages, it made your code self-documenting and it ensured…

DodgyCodeException
- 163
- 6
3
votes
1 answer
To inherit or to override?
Imagine that I am writing a game where tanks fight with each other.
A generic Tank class is created and has the method fire() which fires a cannon, looks like this Tank::fire() { /* fires a cannon */ }
And then there is a class for BossTank which…

Sunny Pun
- 139
- 4
3
votes
2 answers
How to overwrite function in a sub class that has unique functionality in the middle of the function compared to the parent
sorry if the title is a bit messy but I wasn't sure how to form my question. So I have some classes that I've used for a project that I'm looking to making more general so that I can reuse them for other projects. The idea was to move all code that…

Jesper Evertsson
- 201
- 2
- 6
2
votes
1 answer
How can I enforce that decorator pattern is complete at compile time?
I have a C++ class (Class D) that is a decorator of another class (Class B). Class D inherits from B and also requires an instance of B to construct that it keeps track of. Class D overrides all methods in B and instead calls the same functions on…

Alexis Winters
- 131
- 3
2
votes
1 answer
UML - Changing the visibility of operations when overriding them
I am trying to find out if it is allowed in the UML to change the visibility (access modifier) of an operation when overriding it. For example, in Java it is possible to increase the visibility of an overridden method from protected to…

xoric
- 51
- 6
1
vote
5 answers
Is this a proper use of overriding according to LSP?
I have a abstract class named MotorizedVehicle that contains an implemented gas- and brake-function. I want to make a Truck class that extends this class and uses gas exactly in the same way as MotorizedVehicle, but with the limitation that it can't…

Felix Jönsson
- 95
- 5
1
vote
1 answer
Should you allow user to override normal behavior
This is more of a subjective question and i don't expect a perfect anwser.
I have different behavior/rules in my system.
for example : I have a behavior in my system that allows users to register to the same course multiple time. This behavior is…

Francis Groleau
- 119
- 1
0
votes
4 answers
C# refactoring with inheritance
I have two classes which contains almost same method. How can I refactor this with inheriting one class by other class.
class A{
public void run(){
// task 1
// task 2
// task 3
}
}
class B{
public void run(){
// task 1 …

Buddhika Chathuranga
- 115
- 6
0
votes
3 answers
Overriding methods with stricter signature
I'm programming in Java and have the following problem:
I would like to do collision detection. For that, I need different types of BoundingBoxes. For the sake of example, let's say that I have entities that have a circular collision box and…

PawkyPenguin
- 251
- 1
- 2
- 6
0
votes
2 answers
Question on members in derived classes (new vs override)
I'm working through the Head First Design Patterns book and am currently on the Decorator Pattern chapter. Since the book examples are written in Java, I'm adapting the, to C# as I go.
This example simulates a coffee shop ordering system. There is…

Jim
- 1,997
- 3
- 20
- 25
-1
votes
2 answers
Should we override all method overloads
Usually method overloads delegate their parameters to the more detailed overloads with default values. here is an example
A(x) => A(x, null);
A(x, y) => A(x, y, null);
A(x, y, z) => ...;
What should I do if i want to override this method and do a…

M.kazem Akhgary
- 111
- 5
-1
votes
1 answer
How should I represent an object whose instances share the same set of member function identifiers, but those identifiers specify different behaviors?
I'm attempting to develop an open-source Python module for modeling task networks for discrete event simulation. The most fundamental component is the task object, which includes various data such as a distribution of possible task duration times, a…

mcman
- 1
- 2