Wanted to create an interface for DAOs that can be "overloaded" with different method params types:
abstract class DaoInterface {
Future<List<Object?>> findAll();
Future<Object?> findOne(int id);
Future<Object?> insert<T>(T value);
Future<Object?> update(Object dto);
Future<Object?> deleteOne(Object dto);
Future<Object?> deleteAll();
}
// impl
class CategoryDAO implements DaoInterface {
@override
Future<CategoryEntity?> deleteAll() {
// TODO: implement deleteAll
throw UnimplementedError();
}
@override
Future<CategoryEntity?> deleteOne(CategoryEntity category) {
// TODO: implement deleteOne
throw UnimplementedError();
}
@override
Future<List<CategoryEntity?>> findAll() {
// TODO: implement findAll
throw UnimplementedError();
}
@override
Future<CategoryEntity?> findOne(int id) {
// TODO: implement findOne
throw UnimplementedError();
}
@override
Future<CategoryEntity?> update(CategoryEntity category) {
// TODO: implement update
throw UnimplementedError();
}
@override
Future<CategoryEntity?> insert(CategoryEntity entity) {
// TODO: implement insert
throw UnimplementedError();
}
}
the above throws warnings for insert, update, deleteOne methods, ie:
'CategoryDAO. insert' ('Future<CategoryEntity?> Function(CategoryEntity)') isn't a valid override of 'DaoInterface. insert' ('Future<Object?> Function(T)'). (Documentation) The member being overridden (dao_interface. dart:9).
I've tried using Object base class, generics, etc- and nothign seems to allow this behavior. I expected to implement this interface for other DAOs that take different entity classes to reduce code duplication (PersonDAO using PersonEntity, etc). Thoughts? Am I approaching this incorrectly?