public abstract class Result{
Result(){}
public final static class Ok extends Result {
public final double [] data;
...
}
public final static class Error extends Result{
private Error(){}
public static final Error Instance = new Error ();
}
}
try{
parse
return new Result.Ok(parsed);
} catch(NFE){
return Result.Error.Instance;
}
if(result instanceOf Result.Ok ok){
use ok.data
} else {
Handle error
}
interface SomethingDependencies {
val dep1: Dep1
val dep2: Dep2
...
val depN: DepN
}
object SomethingFactory {
fun create(dependencies: SomethingDependencies): Something {
return DaggerSomethingComponent.factory().create(dependencies).getImpl()
}
}
interface Something { ... }
internal class SomethingImpl @Inject constructor(
// в конструктор может приходить всякое, как Dep1..DepN, так и другие объекты, построенные на их основе
): Something
@Component(dependencies=[SomethingDependencies::class]
internal interface SomethingComponent {
@Component.Factory
interface Factory {
fun create(dependencies: SomethingDependencies): SomethingComponent
}
fun getImpl(): SomethingImpl
}
@SubComponent
interface MainActivityComponent: SomethingDependencies {
...
}
@Provides
fun something(dependencies: MainActivityComponent): Something { // не забываем, что MainActivityComponent реализует SomethingDependencies
return SomethingFactory.create(dependencies)
}