Skip to content

Fold wiki DI/factory lesson content into core-programming patterns - #15

Merged
aschokking merged 1 commit into
mainfrom
strengthen-di-factory-docs
Oct 3, 2026
Merged

aschokking merged 1 commit into
mainfrom
strengthen-di-factory-docs

Conversation

@aschokking

Copy link
Copy Markdown
Contributor

Follow-up to #14. The curriculum sequence now sends students from Command Groups into these two pages instead of duplicating the wiki's Factories / Power of Injection / DI with Dagger lessons — so these pages need to actually cover what those lessons taught. They didn't.

dependency-injection.md

The missing half: simulation and mocks. The page explained Component, Module and @Inject, but never mentioned SimulationComponent or MockDevicesModule — which is the whole reason DI matters to a student whose unit tests run on a laptop with no robot. New "Real hardware vs. mocks" section covers:

  • RobotComponent (real devices) vs SimulationComponent (mock devices), both extending BaseRobotComponent
  • Robot.createDaggerComponent() choosing between them via BaseRobot.isReal()
  • the MockDevicesModule @Binds that swaps XCANMotorControllerFactory for the mock implementation
  • the payoff: DriveSubsystem asks for a factory and never learns which kind it got, so there is no if (testMode) anywhere in subsystem code

How tests reach into Dagger. Adds the getInjectorComponent().tankDriveWithJoysticksCommand() pattern students see in TankDriveTest, and explains why BaseRobotComponent needs one abstract method per directly-requestable type — while most classes need nothing, since an @Inject constructor is enough.

Smaller fixes: names constructor injection, and fixes public class ShooterSubsystem() { — a class declaration can't take parentheses, so that sample wouldn't compile. (Same bug the wiki version had; fixed there earlier.)

providers-factories.md

A gentler way in. The page opened with "Dagger can inject dependencies, but what if you need objects with runtime values?" — reasonable for someone who already knows Dagger, steep for someone arriving straight from Command Groups. New "What's a Factory?" opener uses the wiki's Car/CarFactory analogy, then connects it to code the student has already written:

this.frontLeft = motorControllerFactory
        .create(new CANMotorControllerInfo("FrontLeft", 1), this.getPrefix(), "FrontLeft");

The existing Dagger-level material follows unchanged.

Also: adds XGyro.XGyroFactory and XSolenoid.XSolenoidFactory to the factory table.

Verification

  • Every class and factory name checked against current SeriouslyCommonLib / XbotEdu sources. The eight factories already in the table all exist; the two added do too.
  • pnpm docs:build passes.

🤖 Generated with Claude Code

The curriculum sequence now routes students from Command Groups into these
two pages instead of duplicating the wiki lessons, so they need to cover what
those lessons taught.

dependency-injection.md:
- new "Real hardware vs. mocks" section: RobotComponent vs SimulationComponent,
  Robot.createDaggerComponent() choosing between them, and the MockDevicesModule
  @BINDS that swaps the motor controller factory. The page had no mention of
  simulation or mocks at all, which is the whole reason DI matters to a student
  running unit tests on a laptop.
- explains how tests pull objects out of Dagger via getInjectorComponent(), and
  why BaseRobotComponent needs a line per directly-requestable type
- names constructor injection
- fixes "public class ShooterSubsystem() {" - a class declaration cannot take
  parentheses, so the sample would not compile

providers-factories.md:
- new "What's a Factory?" opener with the Car/CarFactory analogy and the
  DriveSubsystem motorControllerFactory call students already wrote in Tank
  Drive. The page previously opened at Dagger level, which is a steep start
  for someone arriving from the challenges.
- adds XGyroFactory and XSolenoidFactory to the factory table

All class and factory names verified against the current SeriouslyCommonLib
and XbotEdu sources.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@aschokking
aschokking merged commit 685b9f5 into main Oct 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant