Created
July 18, 2023 20:13
-
-
Save SamJakob/bc9a693d707f95a0356291817f38db1e to your computer and use it in GitHub Desktop.
Backwards-compatible ControllableClient implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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