Skip to content

Instantly share code, notes, and snippets.

@huafu
Created May 28, 2020 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huafu/8237ab5e8b4ca46add5bf5625693c5ec to your computer and use it in GitHub Desktop.
Save huafu/8237ab5e8b4ca46add5bf5625693c5ec to your computer and use it in GitHub Desktop.
inheritance issues
abstract class IQuery {}
abstract class IDocument {}
abstract class IModel {
IQuery buildQuery({
IDocument from, // putting dynamic here doesn't fix the issue
int Function(IDocument, IDocument) clientSort,
// ...
});
}
class Query<D extends IDocument> implements IQuery {}
abstract class DocumentBase<M extends ModelBase<DocumentBase<M>>>
implements IDocument {}
abstract class ModelBase<D extends DocumentBase<ModelBase<D>>>
implements IModel {
Query<D> buildQuery({
D from,
int Function(D, D) clientSort,
});
}
// Without defining it in the base model class:
abstract class DocumentBase2<M extends ModelBase2<DocumentBase2<M>>>
implements IDocument {}
abstract class ModelBase2<D extends DocumentBase2<ModelBase2<D>>>
implements IModel {}
class User extends DocumentBase2<UserModel> {}
class UserModel extends ModelBase2<User> {
Query<User> buildQuery({
User from,
int Function(User, User) clientSort,
}) => null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment