How bad it's have two methods with the same name but differents signatures in two classes?
Posted
by
Super User
on Programmers
See other posts from Programmers
or by Super User
Published on 2013-10-22T20:29:08Z
Indexed on
2013/10/22
22:02 UTC
Read the original article
Hit count: 271
I have a design problem relationated with the public interface, the names of methods and the understanding of my API and my code.
I have two classes like this:
class A:
...
function collision(self):
....
...
class B:
....
function _collision(self, another_object, l, r, t, b):
....
The first class have one public method named collision and the second have one private method called _collision. The two methods differs in arguments type and number. In the API _m method is private.
For the example let's say that the _collision method checks if the object is colliding with another_ object with certain conditions l, r, t, b (for example, collide the left side, the right side, etc) and returns true or false according to the case. The collision method, on the other hand, resolves all the collisions of the object with other objects.
The two methods have the same name because I think is better avoid overload the design with different names for methods who do almost the same think, but in distinct contexts and classes.
This is clear enough to the reader or I should change the method's name?
© Programmers or respective owner