Click to See Complete Forum and Search --> : Identifying method names


TubularX
October 19th, 2008, 11:21 AM
If I want to add a copy method to my "Car" class, is it better to name it "CopyCar()" than just "Copy()"?

That would make it easy to search for all places where the specific copy method was called, as opposed to if every class had a copy method with the same name (for every search result, you would have to consider the context). Is this of importance or not?

If the class was inherited, the method name would of course depend on the base class (if it's intended to be used polymorphically). Also here, the shared name could be either "Copy" or let's say "CopyVehicle".

What do you recommend? Advantages and disadvantages of adding the class name to the end of common method names?

TheCPUWizard
October 19th, 2008, 11:50 AM
The method should identify JUST the action. The class (static) or instance will determine the details (along with the parameters).

Even if you have 100 classes that do not have any type of inheritance relation ship, but still have general concept in common, they should all have the exact same method name.