ResoCoder / flutter-tdd-clean-architecture-course

https://resocoder.com/flutter-clean-architecture-tdd/
1.99k stars 623 forks source link

Bloc has hard-coded dependency on concrete use case type #18

Open dalewking opened 4 years ago

dalewking commented 4 years ago

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>

DanielSoCra commented 4 years ago

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

dalewking commented 4 years ago

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.