I have this sample code for use cases:
final class AuthUseCases {
final DataProxy dataProxy;
const AuthUseCases(this.dataProxy);
Future<AuthSession> login(TCredential credential) async {
// a lot of lines here...
}
AuthSession logout(AuthSession session) {
// a few lines here...
}
}
and I have this sample code for BloC events by using Freezed package:
@freezed
sealed class TmdbEvent with _$TmdbEvent {
const factory TmdbEvent.login(TCredential credential) = LoginEvent;
const factory TmdbEvent.logout() = LogoutEvent;
}
class TmdbBloc extends Bloc<TmdbEvent, PageState> {
// more lines here...
}
So I was asking myself if I could join these classes together because I think BloC events are the same as use-cases. So some questions here:
- is that idea correct?
- how would this new class look like? I'm new with Freezed package
- is it a good idea to keep a single class or have them separate?
Your idea of combining
BloC eventswith use cases is reasonable, as both are concerned with handling business logic and representing actions within your application. However, it's crucial to maintain a clear separation of concerns. While they can share similarities, it's often beneficial to keep them as distinct entities for better code organization and maintainability.Here's suggestion:
However, remember that the decision to combine or separate classes depends on factors like code complexity, maintainability, and adherence to the Single Responsibility Principle. If the class becomes too large or complex, it might be beneficial to split it into separate use cases and BloC events for better readability and maintainability.