How can I have a Factory method using Android and Hilt/Dagger using the java example code. Is this design pattern possible in Android Hilt/Dagger and how to implement. I can not find a good solution on the web
Thanks John
public class ScannerFactory {
private ScannerFactory() {
}
/**
* Get the scanner device
*
* @param scannerType - The scanner type, one of A or B
* @param context - The apps context
* @return
*/
public static ScannerDevice getScannerDevice(final String scannerType, final Context context) {
if (scannerType.equals("A")) {
return new DeviceA(context);
} else if (scannerType.equals("B")) {
return new DeviceB(context);
}
throw new IllegalArgumentException("Wrong device");
}
}