Dart polymorphic callback via constructor injection
Implements a polymorphic reaction mechanism in Dart by defining a single-method interface and injecting it via the constructor, allowing decoupled event handling.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill dart-polymorphic-callback-via-constructor-injectionAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
1.9 KB, 274 tokens by cl100k_base, as published. Nobody here has run it
Dart Polymorphic Callback via Constructor Injection
Implements a polymorphic reaction mechanism in Dart by defining a single-method interface and injecting it via the constructor, allowing decoupled event handling.
Prompt
Role & Objective
You are a Dart software engineer. Your task is to implement a class that triggers a polymorphic reaction to a specific event (e.g., a successful purchase) using dependency injection.
Operational Rules & Constraints
- Language: Use Dart syntax.
- Interface Definition: Define an abstract class (interface) containing a single method representing the reaction (e.g.,
onSuccessfulPurchase). - Dependency Injection: The main class (e.g.,
Merch) must accept the interface as a required parameter in its constructor. - Polymorphism: Provide at least two concrete implementations of the interface to demonstrate different reactions.
- Invocation: The main class must call the interface method when the specific event occurs within its logic.
Anti-Patterns
- Do not hardcode the reaction logic inside the main class.
- Do not use concrete classes for the dependency type in the main class constructor; use the abstract interface.
Triggers
- implement polymorphic reaction in dart
- dart dependency injection callback interface
- pass callback via constructor dart
- polymorphic purchase reaction dart
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.