{"id":5895,"date":"2024-06-27T17:09:58","date_gmt":"2024-06-27T15:09:58","guid":{"rendered":"https:\/\/oopm.org\/?page_id=5895"},"modified":"2025-03-18T22:12:48","modified_gmt":"2025-03-18T21:12:48","slug":"17-1-adressable-aspect","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=5895","title":{"rendered":"18.1 Addressable aspect"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages5895&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=wpv2pages5895&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\">The fact that a number objects from different classes may be addressable is represented by defining a class <code>Address<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Address:\n   country: <strong>var<\/strong> String \n   town: <strong>var<\/strong> String\n   street: <strong>var<\/strong> String\n   streetNo: <strong>var<\/strong> Integer\n   print:\n      country.print\n      town.print\n      street.print\n      streetNo.print \n   change(newAddr: <strong>ref<\/strong> Address):\n      country := newAddr.country\n      town := newAddr.town\n      street := newAddr.street\n      streetNo := newAddr.streetNo<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Address<\/code> objects have the data-items <code>country<\/code>, <code>town<\/code>, <code>street<\/code>, and <code>streetNo<\/code>. The address may be changed by the <code>change<\/code> method, and it may be printed by the <code>print<\/code> method.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Customers being addressable is represented by <code>Customer<\/code> objects having an <code>Address<\/code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-foreground-color\"> <\/mark>object:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Customer:\n   -\"-\n   addr: <strong>obj<\/strong> Address<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The fact that a <code>Customer<\/code> object has an <code>addr<\/code> object as above implies that the attributes of the <code>Address<\/code> object are &#8220;kind of attributes of the <code>Customer<\/code> as well&#8221;, however, they are only indirect attributes as they have to be accessed through <code>addr<\/code>, like e.g.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aCustomer.addr.print<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">where <code>aCustomer<\/code> is a reference to a <code>Customer<\/code> object. The same would be the case inside the class <code>Customer<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Customer: Person\n   -\"-\n   addr: <strong>obj<\/strong> Address\n   ...\n   addr.print\n   ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">One could argue that for <code>Address<\/code> to be an aspect of <code>Customer<\/code>, the properties of <code>Address<\/code> should be directly accessible and not via the name <code>addr<\/code> of the part object. This would have been the case if <code>Customer<\/code> had been a subclass of <code>Address<\/code>, but that is obviously a wrong way to model this situation. A customer would typically <em>be a type<\/em> of e.g. person and it will <em>have<\/em> an address. From a modeling approach, a customer <em>is not<\/em> an address, but a customer <em>has<\/em> an address.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>addr<\/code> object is a simple means to represent an aspect like address, as we use an already known mechanism of an intrinsic object (<strong><code>obj<\/code><\/strong>). However, it should be possible not only to apply a given aspect like <code>Address<\/code> to any class of object, but also to tailor the aspect to the class to which it is applied.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>print<\/code> method of <code>Address<\/code> simply prints the address. If we also would like to print the name of the costumer, then we can not define <code>addr<\/code> simply as an <code>Address<\/code> object. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The usual way of making the <code>print<\/code> method so that it can be tailored in different <code>Address<\/code> aspects of different classes or objects is to define it as a virtual method:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Address:\n   -:-\n   print:&lt;\n      inner(print)  -- whatever to print from the class\/object that has\n                    -- an Address aspect\n      country.print\n      town.print\n      street.print\n      streetNo.print   <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of representing an <code>Address<\/code> aspect just by an <code>Address<\/code> object, the aspect is then rather represented by a singular intrinsic object with <code>Address<\/code> as a superclass and with an extension of the virtual <code>print<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code><strong>class<\/strong> Customer: Person\n   -\"-\n   addr: <strong>obj<\/strong> Address\n      print::\n         name.print<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Because <code>print<\/code> is extended in the context of <code>Customer<\/code>, i.e. nested in the description of <code>Customer<\/code>, the <code>name<\/code> data-item of <code>Customer<\/code> is visible and can therefore be printed in the extension of <code>print<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Aspects may typically be applied to more than one class. Here it is applied to class <code>Bank<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code><strong>class<\/strong> Bank:\n   name: <strong>var<\/strong> String\n   addr: <strong>obj<\/strong> Address\n      print::\n         name.print<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this case <code>print<\/code> will print the name of the bank.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose that we have a class <code>BankCustomer<\/code> that is subclass of <code>Customer<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code><strong>class<\/strong> BankCustomer: Customer\n   bankName: <strong>var<\/strong> String  -- the name of the bank \n                         -- where the bank customer is a customer<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose that we still want to represent the <code>Address<\/code> as an aspect of <code>Customer<\/code>, <em>and<\/em> as an aspect of class <code>BankCustomer<\/code>, but still so that the aspect is tailorable in both <code>Customer<\/code>, in <code>BankCustomer<\/code>, and in further subclasses of <code>BankCustomer<\/code>. Then the above definition of <code>addr<\/code> will not do; we vill then have to define the class of <code>addr<\/code> by a virtual class <code>AddrType<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code><strong>class<\/strong> Customer: Person\n   <strong>class<\/strong> AddrType:&lt; Address\n      print::&lt;\n         inner(print)\n         name.print\n\n   addr: <strong>obj<\/strong> AddrType  \n\n<strong>class<\/strong> BankCustomer: Customer\n   bankName: <strong>var<\/strong> String  \n   <strong>class<\/strong> AddrType::&lt;\n      print::&lt;\n         inner(print)\n         bankName.print<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As the virtual class <code>AddrType<\/code> is defined defined in the context of <code>Customer<\/code>, the virtual print has access to the <code>name<\/code> of <code>Customer<\/code>, so <code>name.print<\/code> will print the <code>name<\/code> of the <code>Customer<\/code>. Note that the <code>print<\/code> method of <code>AddrType<\/code> is an extension of <code>print<\/code> in <code>Address<\/code>, but still virtual (<code>::&lt;<\/code>) so that it can be further extended in the extension of <code>AddrType<\/code> in <code>BankCustomer<\/code>. This extension of <code>AddrType<\/code> is defined in the context of <code>BankCustomer<\/code>, and <code>bankName<\/code> is therefore visible in the further extension of <code>print<\/code>.<\/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=5895\" 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>The fact that a number objects from different classes may be addressable is represented by defining a class Address: Address objects have the data-items country, town, street, and streetNo. The address may be changed by the change method, and it may be printed by the print method. Customers being addressable is represented by Customer objects [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3511,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5895","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\/5895","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=5895"}],"version-history":[{"count":16,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5895\/revisions"}],"predecessor-version":[{"id":11368,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5895\/revisions\/11368"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/3511"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}