Interfaces, Packages, and Code Organization
Keep code navigable as the robot grows.
Keep code navigable as the robot grows.
In this lesson, you will:
Code organization is architecture students can see in the file tree. Packages should make ownership obvious: hardware, subsystems, commands, opmodes, vision, drive, and util.
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.
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); }
}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.
Draw your package tree and explain where a new intake command should live.
Check your understanding before moving on.
0 of 2 answered