Skip to lesson
Westlake RoboticsLearn
Vault

FIRST Tech Challenge

Loading progress…

  • Command-Based OpModes
  • Interfaces, Packages, and Code Organization

Interfaces, Packages, and Code Organization

Keep code navigable as the robot grows.

Command Patterns and Code OrganizationAdvanced

In this lesson, you will:

  • Organize files by responsibility.
  • Use interfaces for shared capabilities.
  • Avoid circular dependencies.

Concept narrative

Code organization is architecture students can see in the file tree. Packages should make ownership obvious: hardware, subsystems, commands, opmodes, vision, drive, and util.

Robot mental model

A clean package structure helps new programmers find the right file. Interfaces are useful when different mechanisms expose the same capability, such as resettable or telemetry-reporting behavior.

Implementation walkthrough

Create packages before the codebase becomes chaotic. Move one utility into util, one mechanism into subsystem, and one action into command. Keep imports readable.

PackageExample.javaJava

public interface Resettable {
    void reset();
}

public class ArmSubsystem implements Resettable {
    @Override public void reset() { updateState(ArmState.SAFE); }
}

Common mistakes and debugging

If files import across every package, ownership is muddy. If an interface has only one implementation and no clear purpose, it may be unnecessary. Keep organization simple but intentional.

Practice

Draw your package tree and explain where a new intake command should live.

Checkpoint

  • Package names match responsibilities.
  • Interfaces have a real reason.
  • New files have obvious homes.
  • The test record includes the setup, prediction, and observed result.
  • A teammate can repeat the check from the saved evidence without guessing.

Reflection check

Check your understanding before moving on.

What does a Resettable interface communicate about a subsystem?
Why organize robot code into packages by responsibility?

0 of 2 answered

References

Learn Java for FTCFTC-focused Java book and exercises by Alan G. Smith.FIRST FTC DocsOfficial SDK, Robot Controller, and programming reference.Game Manual 0FTC community reference for programming, controls, and robot design.
Loading lesson progress
Previous lessonCommand-Based OpModesNext lessonP Control Basics