This project demonstrates composition in Dart using a container class (FarmController
) and multiple part classes (WaterPump
, ChickenCoop
, Tractor
).
The container delegates actions to its parts, showing how composition can combine smaller classes into a larger system.
-
Container:
FarmController
- Holds references to
WaterPump
,ChickenCoop
, andTractor
- Provides two methods:
morningRoutine()
→ starts pump, feeds chickens, plows fieldnightRoutine()
→ parks tractor, locks coop, stops pump
- Holds references to
-
Parts:
WaterPump
→ simulates irrigation pump with start/stopChickenCoop
→ manages feeding chickens and locking the coopTractor
→ simulates fieldwork with plow/park actions
-
Demo:
main.dart
- Instantiates the parts
- Passes them into the
FarmController
(constructor injection) - Runs both routines and prints labeled console output
-
[AgriHub-01] → Container class (
FarmController
) -
[EastPump] → Part class (
WaterPump
) -
[SouthCoop] → Part class (
ChickenCoop
) -
[RedTractor] → Part class (
Tractor
)