Is it possible to create slightly varying instances of a class based on two parameters A and B so that
- If A and B are present --> create instance variation AB
- If A and not B are present --> create instance variation A
- If not A and B are present --> create instance variation B
- If neither A nor B are present --> do not allow instance creation
Is this kind of parameter "or" even possible? Should I create guards or use switch case and branch to different subclasses? Or is there a way to use factories? I tried using factories before, but because the returning instances should have the same base class I am having problem creating this common base for them.
The class I am trying to create could be something like this:
class WeirdProblem extends StatelessWidget {
WeirdProblem({
Key? key,
this.A,
this.B,
this.someParam = someValue,
required anotherParam,
}) : super(key: key);
final SomeType? A;
final AnotherType? B;
final Type someParam;
final Type anotherParam;
/// How to create the instances so that the
/// parameters A and B are logically or'd?
}
class AB extends StatelessWidget {
AB({
required A,
required B,
})
...
}
class A extends StatelessWidget {
A({
required A,
})
...
}
class B extends StatelessWidget {
B({
required B,
})
...
}
/// class without A and B doesn't exist