Suppose we have a vehicle, which gets its position from an IMU. The IMU package consists of several private components, which it orchestrates to calculate the vehicle's state in space:
with IMU; use IMU;
Package Vehicle is
...
end vehicle;
Package IMU is
type Attitude is record
Lat, Lon: Angle;
Pitch, Roll, Yaw: Angle;
GroundSpeed: Speed;
...
end record
function Get_Position return Attitude is ...
Package GPS is
...
end GPS;
Package Accelerometer is
...
end Accelerometer;
Package Gyro is
...
end Gyro;
end IMU;
The internals of GPS, Accelerometer and Gyro only make sense in the context of the IMU; they must be completely hidden from Vehicle.
Declaring the IMU and all of its sub-components in a single source file will be difficult to read and maintain; I'd like to have each sub-component in it's own source file. If I code them all at the IMU level, the vehicle will be able to access the GPS, which is wrong.
What is the best practice for structuring nested packages?