Skip to content

Instantly share code, notes, and snippets.

@fardhanardhi
Last active May 13, 2024 12:20
Show Gist options
  • Save fardhanardhi/547b88616e5583516a1fa63f4f2af130 to your computer and use it in GitHub Desktop.
Save fardhanardhi/547b88616e5583516a1fa63f4f2af130 to your computer and use it in GitHub Desktop.
Multiple-generic abstraction

Dart Generic Type OOP

Multiple generic abstraction

This code structure promotes flexibility and code reusability. By using abstract classes and generics, you can create an executor for different types of calculations while ensuring type safety and consistency.

Declaration

import 'dart:async';

abstract class A<U extends Param, T> {
  A();
  FutureOr<T> calculate(U a);
}

abstract class B<int> extends A<ParamImpl, int> {
  B();
  @override
  int calculate(ParamImpl b);
}

abstract class Param {}

Implementation

class ParamImpl extends Param{}

class BImpl implements B {
  @override
  int calculate(ParamImpl b){return 0;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment