There is some object say, ABC, which I get in different ways. I have added all these methods to get the object ABC in a separate class. Now my question is how should I name this class? I have named it ABCHelper which I know is not an appropriate name. I also don't want to name it util, else I have to keep static methods which I want to avoid. Could you please suggest me any appropriate name for such class.

public class ABCHelper {

    public List<ABC> getABC(Source1 source1, ParameterType1 parameter1) {
        // There are more lines of code here. 
        // Showing only this much for simplicity.
        return source1.getABC(source1, method1);  
    }

    public List<ABC> getABC(Source1 source1, ParameterType2 parameter2) {
        return source1.getABC(source1, method1);
    }

    public List<ABC> getABC(Source2 source1, ParameterType3 parameter3) {
        return source1.getABC(source1, method1);
    }

    public List<ABC> getABC(Source2 source1, ParameterType4 parameter4) {
        return source1.getABC(source1, method1);
    }
}
New contributor
Mukesh is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

put on hold as primarily opinion-based by Andreas, TylerH, John Dvorak, rene, Radiodef 13 mins ago

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    If the methods of that class are in fact utility methods and use no instance fields of the class, then why shouldn't they be static? – Hovercraft Full Of Eels 34 mins ago
  • Are the 4 method1 argument not supposed to be parameter1 ... parameter4? – Andreas 32 mins ago
  • 1
    Why would you need to pass source1 in as a parameter to an instance method of source1? – Andreas 31 mins ago

I have added all these methods to get the object ABC in a separate class.

It's a good case for defining static factory methods within the class ABC. Along with giving these methods meaningful names (e.g. ABC.getFromSource1), it's the first option I would suggest you consider.

Could you please suggest me any appropriate name for such class.

Define a single responsibility that your class will be taking. Choose the right noun for that role. It might be Initialiser, Creator, Producer, Supplier, etc.

Welcome to StackOverflow. This is not a naming issue, but the design issue. Try to avoid names like *Helper and *Utils. I suggest you create a class extending ArrayList<ABC> which would have constructors of this class would accept those parameters. The constructor of inherited class accepts another collection (public ArrayList(Collection<? extends E> c)) which is useful in case the method getABC returns List<ABC> which is a Collection itself.

public class AbcList extends ArrayList<ABC> {

    public AbcList(Source1 source1, ParameterType1 parameter1) {
        super(source1.getABC(source1, method1));
    }

    public AbcList(Source1 source1, ParameterType2 parameter2) {
        super(source1.getABC(source1, method2));
    }

    // ...
}

If you insist to use a class with a bunch of static methods, I suggest you the Factory design pattern which implies the possible names of the class:

  • public class AbcFactory
  • public class AbcListFactory
  • A constructive reason for a downvote? Any mistake I can correct? – Nikolas 21 mins ago
  • 2
    using inheritance like this is vile, and unnecessary: if you want ArrayLists that contain the results of source1.getABC (etc) do that, but do it in a factory method that creates a regular ArrayList. And the "biggest advantage" is a violation of the contract of ArrayList: ArrayList cannot be made immutable without violating Liskov substitutability (not that overriding add makes it immutable, anyway, but I assume you mean "and override all of the other mutating methods too"). – Andy Turner 13 mins ago
  • could you elaborate on "Try to avoid names like *Helper and *Utils"? (you meant "avoid", right?) – Andrew Tobilko 9 mins ago
  • @AndyTurner: Thanks a lot. I prefer to treat objects to represent something themselves over exposing them through factory methods. About LSP, thanks for the explanation. – Nikolas 6 mins ago

You can try naming it *Provider if it suits your requirement. I.e if your class is used to provide manipulated list from source then you can do it like : DataModel is your any source class then use it as,

public class DataModelProvider {

public List<Data> getData(Source1 source1, ParameterType1 parameter1) {
    // There are more lines of code here. 
    // Showing only this much for simplicity.
    return source1.getData(source1, method1);  
}

public List<Data> getData(Source1 source1, ParameterType2 parameter2) {
    return source1.getData(source1, method1);
}

public List<Data> getData(Source2 source1, ParameterType3 parameter3) {
    return source1.getData(source1, method1);
}

public List<Data> getData(Source2 source1, ParameterType4 parameter4) {
    return source1.getData(source1, method1);
}}

Even though, you can try some suffix for your class like Dto, Entity, Bean etc. based on your structure. (More like code design pattern)

New contributor
Jeel Vankhede is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.