flutter-tdd-clean-architecture-course icon indicating copy to clipboard operation
flutter-tdd-clean-architecture-course copied to clipboard

Bloc has hard-coded dependency on concrete use case type

Open dalewking opened this issue 5 years ago • 2 comments

You have this:

class NumberTriviaBloc extends Bloc<NumberTriviaEvent, NumberTriviaState> {
  final GetConcreteNumberTrivia getConcreteNumberTrivia;
  final GetRandomNumberTrivia getRandomNumberTrivia;

Which is hardcoding a dependency on GetConcreteNumberTrivia and GetRandomNumberTrivia types.

Shouldn't that really be:

class NumberTriviaBloc extends Bloc<NumberTriviaEvent, NumberTriviaState> {
  final UseCase<NumberTrivia, Params> getConcreteNumberTrivia;
  final UseCase<NumberTrivia, NoParams> getRandomNumberTrivia;

where Params would be a type (probably better named) in entities or better yet just use int instead and make GetConcreteNumberTrivia implement UseCase<NumberTrivia, int>

dalewking avatar Dec 22 '19 23:12 dalewking

Imho, the UseCase itself is an abstraction, so there is no need to abstract it again.

DanielSoCra avatar Jan 15 '20 15:01 DanielSoCra

It isn't as problematic as it would be in Java where you don't have implicit interfaces, but any time you can reduce dependencies it is a good thing.

I am not saying that an abstraction needs to be created. The UseCase abstraction already exists and I am just suggesting that the existing abstraction is used instead of the concrete class. The only issue then is where Params is declared.

dalewking avatar Jan 15 '20 16:01 dalewking