M
M
mystdeim2016-10-06 17:16:49
Java
mystdeim, 2016-10-06 17:16:49

What is the best way to organize a factory method?

The task is this: a factory method is used to determine a specific implementation, something like this:

public static BaseCommand get(String cmd) throws CMDException {
        if (All.CMD.equalsIgnoreCase(cmd)) return new All();
        ...
        throw new CMDException(String.format("No suitable command for '%s'", cmd));
    }

This method began to grow actively, what is the best way to reproject, not to do a hundred if or a giant switch?
I have an idea to do on annotations

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Kalashnikov, 2016-10-06
@zo0m

As an option - Map

R
Rsa97, 2016-10-27
@slo_nik

General table of photos and three tables of links with tours, tourists and instructors.

A
Alexander Sisyukin, 2016-10-27
@Caarl

Indicate the type, that is, you have tours, tourists, etc. ... that is, the id transfer is repeated for tourists and tours, but they have different types and make a selection not by id, but by id and type

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question