Skip to content

Instantly share code, notes, and snippets.

@SamJakob
Created July 18, 2023 20:13
Show Gist options
  • Save SamJakob/bc9a693d707f95a0356291817f38db1e to your computer and use it in GitHub Desktop.
Save SamJakob/bc9a693d707f95a0356291817f38db1e to your computer and use it in GitHub Desktop.
Backwards-compatible ControllableClient implementation.
mixin ClientControllerSupport {}
abstract class Client {
void doSomething();
static isControllable(Client client) {
return client is ClientControllerSupport;
}
}
class BaseClient extends Client {
@override
void doSomething() {
print("Howdy!");
}
}
class AuthClient implements Client {
@override
void doSomething() {
print("Hello, world!");
}
}
class NewAuthClient with ClientControllerSupport implements Client {
@override
void doSomething() {
print("Hello, new world!");
}
}
class OtherNewAuthClient extends BaseClient with ClientControllerSupport {}
void main() {
AuthClient authClient = AuthClient();
NewAuthClient newAuthClient = NewAuthClient();
OtherNewAuthClient otherNewAuthClient = OtherNewAuthClient();
print("authClient (e.g., legacy API)");
authClient.doSomething();
print(Client.isControllable(authClient));
print("");
print("newAuthClient (e.g., updated to support RequestController API)");
newAuthClient.doSomething();
print(Client.isControllable(newAuthClient));
print("");
print("otherNewAuthClient (e.g., extends BaseClient)");
otherNewAuthClient.doSomething();
print(Client.isControllable(otherNewAuthClient));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment