I
I
IndependenceLetter2019-12-27 20:07:30
Java
IndependenceLetter, 2019-12-27 20:07:30

Why such a relationship between classes (Trip has Airplane)?

I am writing an OOP task (airlines) according to the TK, according to the TK, interfaces are provided that cannot be changed and the implementation should not have anything superfluous ( don`t violate your interface implementations by adding more methods etc). Stupidly following the TK, I don’t see anything complicated, but the following confuses:

interface ITrip
{
 //getters like id, itinerary
public IAirplane Airplane();  
}
interface IAirplane // есть 2 подвида самолетов
{
// содержит в себе коллекцию пассажиров, добавляет/удаляет пассажиров
}

There is an Airport that creates Trips, passengers and there is a CheckIn method (I think it is clear from the logic what should be done => checkin a passenger). So here is the logic of this method to take all the available Trips and see through their planes whether the passenger is on some other plane and if so => ​​Exception. )
Question Why is there such a connection between planes and trips?? With airplanes, it’s clear that they contain passengers, but why does the trip have an airplane? (I understand that 1 plane = several trips, 1 trip = 1 plane)
But still I can’t accept what is wrong? And the CheckIn logic seems to be over honestly...
UPD: Array of trips in the Airport, but Aircraft don't know anything about trips.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2019-12-27
@IndependenceLetter

Obviously, this refers to the life of the airport in dynamics. That is, not to fill it with data and shut up, but to conduct departures and arrivals, put passengers on planes, etc.
Trip is a route, and several routes can travel on one plane (for example, with landings, or a charter flight in general and several travel agencies fill the plane).

D
Denis Zagaevsky, 2019-12-27
@zagayevskiy

Yes, all these tasks "on OOP" with inheritance hierarchies sucked from the finger, as you put it, are "down". Do not think, there is no logic there, the author never wrote real code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question