How bad is it to have two methods with the same name but different 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/28 16:14 UTC
Read the original article Hit count: 281

I have a design problem related to a public interface, the names of methods, and the understanding of my API and 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 has one public method named collision, and the second has one private method called _collision. The two methods differs in argument type and number.

As an example let's say that _collision checks if the object is colliding with another object with certain conditions l, r, t, b (collide on the left side, right side, etc) and returns true or false. The public 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 it's better to avoid overloading the design with different names for methods that do almost the same thing, but in distinct contexts and classes.

Is this clear enough to the reader or I should change the method's name?

© Programmers or respective owner

Related posts about design-patterns

Related posts about software