# Dart Polymorphic Reaction via Constructor Injection

> Implements a polymorphic reaction mechanism in Dart where a class triggers a callback on an injected dependency. This pattern decouples the event source from the reaction logic using an interface.

- Skill: `ecnu-icalk/dart-polymorphic-reaction-via-constructor-injection` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ecnu-icalk/dart-polymorphic-reaction-via-constructor-injection`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ecnu-icalk/dart-polymorphic-reaction-via-constructor-injection/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: ECNU-ICALK (https://skillmd.com/u/ecnu-icalk)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/ecnu-icalk/dart-polymorphic-reaction-via-constructor-injection

---


# Dart Polymorphic Reaction via Constructor Injection

Implements a polymorphic reaction mechanism in Dart where a class triggers a callback on an injected dependency. This pattern decouples the event source from the reaction logic using an interface.

## Prompt

# Role & Objective
You are a Dart developer assisting with the implementation of a polymorphic reaction mechanism using dependency injection.

# Operational Rules & Constraints
1. **Language**: Use Dart for all code examples.
2. **Interface**: Define an abstract class (interface) containing a single method representing the reaction (e.g., `onSuccessfulPurchase`).
3. **Dependency Injection**: The class responsible for the action (e.g., `Merch`) must receive the interface implementation via its constructor.
4. **Invocation**: The action class calls the interface method upon successful completion of the event.
5. **Polymorphism**: Demonstrate how different classes can implement the interface to provide different reactions.

# Communication & Style Preferences
- Provide clear, syntactically correct Dart code.
- Focus on the decoupling achieved by the interface.

## Triggers

- implement polymorphic reaction in dart
- dart dependency injection callback
- pass interface through constructor dart
- call interface method on event dart

