I have a Flight
class which represents a flight in a pilot's logbook. It is composed of the following attributes:
- duration
- landings
- remarks
It also has an airport and time of both departure and arrival, which are related to my question.
I have though about modeling the the arrival and the departure as a Movement
, which would be composed of the airport and the time. I would then derive a Departure
and an Arrival
class from the Movement
, and have the Flight
reference one of both.
Then I bumped into a discussion on Ruby's TrueClass
and FalseClass
(Why does Ruby have TrueClass and FalseClass instead of a single Boolean class?). The gist of it was that Ruby does not model true
and false
as a Boolean
because they do not share any behavior and I believe the same goes for an arrival and a departure. They are exactly opposite even though they do share data.
Another option is that I simply embed the arrival and departure's data fields in the Flight
. I find this awkward because that would mean that if you would traverse from the Airport
model to the departures and arrivals (has_many :departures
, has_many :arrivals
) would yield a Flight
model.
A third option I explored is creating separate Departure
and Arrival
models without inheriting from a Movement
. However, since a Flight
is required to have both and arrival and a departure, which are required to reference flight, we have created a nasty circular reference (which also plagues the first option, by the way).
How would I best model this relationship? Are there any alternatives I have failed to consider?