Overload or different naming ?

I need two methods which will bring me some data.

1st scenario: bring the data from the file system.

   Method name: GetData(string directory, string[] files)

2nd scenario: bring the data from a dll (assembly) file. The data is an embedded Resource inside the assembly.

   Method name: GetData(string assemblyName, string prefixPath, string[] files)

They both sit in some Helper (static)class.

Now, I thought about changing the method names into GetDataFromFS and GetDataFromAssembly. The fact that they are both serve the same purpose makes me feel that this should be a simple overload but yet I feel that this is wrong somehow due to the fact that their domain is quite different. If tomorrow I’ll add GetData(string webServiceUrl, string[] files) should it be overload as well? I must say I’m not so sure…

What do you think ? overload or naming by domain[1] ?

[1] – No. I don’t want some factory and concrete classes or strategy pattern implementation; This should be a simple utils class.


Oren Ellenbogen


5 thoughts on “Overload or different naming ?

  1. I’m generally against method overloading, except where neccessary, which in the case of C# means "constructors".

    Starting down the path of overloading leads to parameterSPLOSION. Or at least, it does with me.

    (Objective-C handles this kind of thing nicely, since methods with different numbers of parameters are different methods; the argument names are part of the method signature aka "selector".)

    In my .NET code I have a lot of "..WithXyz" and "…FromXyz" methods. When I go back and look at some code a month later I know exactly which "overload" is being used, something I can’t say for construction of various Streams, Readers and Writers using the framework.

  2. Dude!
    Definitely different names.
    Overloads are for two methods that do the same action (read from file) but in a slightly different manner.
    But the major problem here is "GetData". What is that? You must be kidding me.

    p.s. You rock.


  3. I agree with you all, two methods will be much better.

    @Pasha – good to hear from you man,
    The GetData is just for the example. (in reality it’s CompileTemplates)

    Thanks for the comments guys.

  4. I don’t agree with the others.

    I think overloading is the way to go and the reason is totally opposite from what Ayende have said. The methods have the same behaviour for the calling class, but internal they have different behaviour, another implementation.

Comments are closed.