{"id":5004,"date":"2024-06-10T21:05:40","date_gmt":"2024-06-10T19:05:40","guid":{"rendered":"https:\/\/oopm.org\/?page_id=5004"},"modified":"2025-01-14T12:43:42","modified_gmt":"2025-01-14T11:43:42","slug":"10-2a-abstract-flight","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=5004","title":{"rendered":"10.2 Flight example"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages5004&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages5004&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">In this chapter we illustrate nested classes by an example in the domain of flights and flight routes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An airline company like SAS has a timetable with all their flight routes with flights, e.g. SK SK 1926 from Aarhus in Denmark to Oslo in Norway, and SK 1927 from Oslo to Aarhus.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img fetchpriority=\"high\" decoding=\"async\" width=\"611\" height=\"119\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/01\/Route1926and1927.jpg\" alt=\"\" class=\"wp-image-3118\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/01\/Route1926and1927.jpg 611w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/01\/Route1926and1927-300x58.jpg 300w\" sizes=\"(max-width: 611px) 100vw, 611px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A time table is used for two different purposes: as a basis for bookings, e.g. as in the chapter on travel bookings, and as a basis for a website that shows the status of flights at a specific airport, i.e. whether flights are on time, cancelled, delayed, have a new scheduled time of arrival, have arrived and at what time, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Time tables, flight routes and flights are obviously represented by objects. A timetable has an entry for each of the different flight routes, and in the model each entry is represented by an object of class&nbsp;<code>FlightRoute<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code>timeTable: <strong>obj<\/strong> \n   entries: <strong>obj<\/strong> OrderedList(FlightRoute)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each\u00a0<code>FlightRoute<\/code>\u00a0object has attributes that represent the flight number of the flight route, the source and destination airports, the scheduled departure and arrival time, and scheduled flying time. The flights of a route is represented by a list of\u00a0<code>Flight<\/code>\u00a0objects for each\u00a0<code>FlightRoute<\/code>\u00a0object.<\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code><strong>class<\/strong> FlightRoute(flightNumber, origin, destination: <strong>var<\/strong> String): \n   scheduledDepartureTime: <strong>var<\/strong> TimeOfDay           \n   scheduledArrivalTime: <strong>var<\/strong> TimeOfDay \n   setTime(dt: <strong>var<\/strong> TimeOfDay, at: <strong>var<\/strong> TimeOfDay):<mark>\n<\/mark>      scheduledDepartureTime := dt\n      scheduledArrivalTime := at \n   \n   flights: <strong>obj<\/strong> OrderedList(Flight)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>scheduledDepartureTime<\/code>&nbsp;and&nbsp;<code>scheduledArrivalTime<\/code>&nbsp;are used for showing flight status, at airports or at the flight status website of the airline company. The type <code>TimeOfDay<\/code> is defined in section <script>mkRef(\"Composite values\")<\/script>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Setting up the flight routes of the time table is done by a sequence of computations that generate\u00a0<code>FlightRoute<\/code>\u00a0objects, set the values of their attributes and insert them into the\u00a0<code>timeTable<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code>   SK1926: <strong>obj<\/strong> FlightRoute(\"SK1926\", \"AAR\", \"OSL\")\n   Sk1926.setTimes(TimeOfDay(12.30 hours), TimeOfDay(13.50 hours))\n\n   timeTable.entries.insert(SK1926)\n   ...\n   SK1927: <strong>obj<\/strong> FlightRoute(\"SK1927\", \"OSL\", \"AAR\")\n   SK1927.setTimes(TimeOfDay(14.20 hours), TimeOfDay(15.40 hours))<mark>\n<\/mark>\n   timeTable.entries.insert(SK1927)\n   ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As mentioned<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-foreground-color\"> <\/mark>above, flights are represented by objects. As the notion of flight is defined in the context of flight route, the class&nbsp;<code>Flight<\/code>&nbsp;is defined in the context of the class&nbsp;<code>FlightRoute<\/code>. This is done by nesting the description of class <code>Flight<\/code> in the description of class <code>FlightRoute<\/code>:<\/p>\n\n\n\n<pre id=\"block-72f7fdaa-bcf9-4388-8528-8799dd0cb2eb\" class=\"wp-block-code\"><code>   <strong>class<\/strong> FlightRoute(flightNumber, origin, destination: <strong>ref<\/strong> String):   \n      <mark style=\"background-color:rgba(0, 0, 0, 0);color:#454444\" class=\"has-inline-color\">scheduledDepartureTime: <strong>var<\/strong> TimeOfDay \n      scheduledArrivalTime: <strong>var<\/strong> TimeOfDay <\/mark>\n      -\"-\n      <strong>class<\/strong> Flight(departureDate: <strong>var<\/strong> Date):   \n         departureTime: <strong>var<\/strong> TimeOfDay  \n         arrivalTime: <strong>var<\/strong> TimeOfDay\n         delayDeparture(newTime: <strong>var<\/strong> Time.Hours):\n            delayed := True\n            departureTime := newTime\n         delay -&gt; period: <strong>var<\/strong> Time.Hours:\n            period := arrivalTime \u2013 scheduledArrivalTime<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-24d9c449-3fe9-46bb-9a9d-97e9f2757063\">The type <code>Date<\/code> is defined in section <script>mkRef(\"Composite values\")<\/script> and the type <code>Time.Hours<\/code> is defined in section <script>mkRef(\"Dimensions and units\")<\/script>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-24d9c449-3fe9-46bb-9a9d-97e9f2757063\">Note that <code>FlightRoute<\/code> objects keep the flights for any date, while each <code>Flight<\/code> object has its departure date as an attribute.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-24d9c449-3fe9-46bb-9a9d-97e9f2757063\">Departure time is represented by <code>departureTime<\/code>. Before take off it represents the scheduled\/estimated departure time. After take off it represents the actual departure time.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-24d9c449-3fe9-46bb-9a9d-97e9f2757063\">The scheduled arrival time is common to all flights on a flight route, while the arrival time of a flight is represented by a variable. Before take off this is set to the <code>scheduledArrivalTime<\/code> and therefore represent the scheduled\/estimated departure time. While flying it is set based upon flying conditions and landing conditions at the destination airport to represent the expected arrival time. After landing it represents the actual arrival time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the flight is delayed, the method <code>delayedDeparture<\/code> may be used to set the estimated departure time. In addition to assign the parameter <code>newTime<\/code> to <code>DepartureTime<\/code>, <code>delayed<\/code> is set to <code>True<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As we have defined the class <code>FlightRoute<\/code>, so that each object of class <code>FlightRoute<\/code> represents a specific flight route, the class <code>Flight<\/code> is therefore defined in the context of class <code>FlightRoute<\/code>. A specific <code>FlightRoute<\/code> object will thereby have its own class <code>Flight<\/code> of objects<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-2-color\"> <\/mark>representing flights on this flight route. Another <code>FlightRoute<\/code> object will have another class <code>Flight<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The modeling of flight routes and flights is illustrated in the following figure. Each flight route is represented by a <code>FlightRoute<\/code> object, and the corresponding flights are represented by <code>Flight<\/code> objects held by the corresponding <code>FlightRoute<\/code> object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"595\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteFlightsAndObjects-1024x595.jpg\" alt=\"\" class=\"wp-image-8450\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteFlightsAndObjects-1024x595.jpg 1024w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteFlightsAndObjects-300x174.jpg 300w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteFlightsAndObjects-768x447.jpg 768w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteFlightsAndObjects.jpg 1441w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The fact that class <code>Flight<\/code> is described nested in the description of class <code>FlightRoute<\/code> is illustrated in the next figure, using a circle-enclosed &#8216;+&#8217; annotated relation between objects of class <code>FlightRoute<\/code> and the class <code>Flight<\/code>. A specific <code>FlightRoute<\/code> object will thereby have its own class <code>Flight<\/code> of objects representing flights on that flight route. Another <code>FlightRoute<\/code> object will have another class <code>Flight<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"468\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteObjectsWithNestedFlight-1024x468.jpg\" alt=\"\" class=\"wp-image-8447\" style=\"width:856px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteObjectsWithNestedFlight-1024x468.jpg 1024w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteObjectsWithNestedFlight-300x137.jpg 300w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteObjectsWithNestedFlight-768x351.jpg 768w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/RouteObjectsWithNestedFlight.jpg 1045w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">FlightRoute objects with nested Flight classes and corresponding objects<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-bc06c2c5-ad67-465f-928e-b87ac977f1ba\">The following illustration shows how nesting is used to compute the delayas the difference between <code>scheduledArrivalTime<\/code> and <code>arrivalTime<\/code>. By nesting the <code>Flight<\/code> class in the <code><code>FlightRoute<\/code><\/code> class, the attributes of <code><code>FlightRoute<\/code><\/code> are directly visible in class <code>Flight<\/code>. The method <code>delay<\/code> (in class <code>Flight<\/code>) may therefore compute the delay of the flight by subtracting the <code>scheduledarrivalTime<\/code> (in the enclosing <code><code>FlightRoute<\/code><\/code>) from the local <code>Flight<\/code> property <code>ArrivalTime<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"849\" height=\"462\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/delay.jpg\" alt=\"\" class=\"wp-image-6887\" style=\"width:674px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/delay.jpg 849w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/delay-300x163.jpg 300w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/delay-768x418.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As mentioned above, we shall use this model of as the difference between <code>scheduledArrivalTime<\/code> and <code>arrivalTime<\/code> and flights for both booking of flights and for showing status of flights. In the next section, we look at what is required for booking, and then for the status of flights.<\/p>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=5004\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>In this chapter we illustrate nested classes by an example in the domain of flights and flight routes. An airline company like SAS has a timetable with all their flight routes with flights, e.g. SK SK 1926 from Aarhus in Denmark to Oslo in Norway, and SK 1927 from Oslo to Aarhus. A time table [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":1232,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5004","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5004"}],"version-history":[{"count":81,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5004\/revisions"}],"predecessor-version":[{"id":11114,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5004\/revisions\/11114"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/1232"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}