{"id":3092,"date":"2024-01-29T12:01:11","date_gmt":"2024-01-29T11:01:11","guid":{"rendered":"https:\/\/oopm.org\/?page_id=3092"},"modified":"2025-01-17T09:33:54","modified_gmt":"2025-01-17T08:33:54","slug":"46-composite-objects","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=3092","title":{"rendered":"17. Composite objects"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages3092&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=wpv2pages3092&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 the this chapter, we show how to define <em>composite objects<\/em>. A composite object consists of other objects. For material objects, we use intrinsic objects (declared using the keyword <strong><code>obj<\/code><\/strong> (section <script>mkRef(\"Reference data-items\")<\/script>)) to represent possible parts. We will use the term <em>part object<\/em> for an intrinsic object that represents a part of a composite object. For value objects, composite objects are declared by using <code><strong>var<\/strong><\/code> or <strong><code>val<\/code><\/strong>. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A part-object may itself have part-objects and in this way be structured as a composition-hierarchy. Composition is analogous to classification and contextualization, that all are important conceptual means for understating and structuring our knowledge about the real world and thus of a given application domain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A first very simple example of a composite object is a model of a multi-function printer, that is a printer that in addition to printing also can scan and copy. It consists of a <code>Printer<\/code> part-object and a <code>Scanner<\/code> part-object.<\/p>\n\n\n\n<div class=\"wp-block-media-text is-stacked-on-mobile\" style=\"grid-template-columns:34% auto\"><figure class=\"wp-block-media-text__media\"><img fetchpriority=\"high\" decoding=\"async\" width=\"341\" height=\"317\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/MFprinterComposition-1.jpg\" alt=\"\" class=\"wp-image-8574 size-full\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/MFprinterComposition-1.jpg 341w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/MFprinterComposition-1-300x279.jpg 300w\" sizes=\"(max-width: 341px) 100vw, 341px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Printer:\n   print(doc: <strong>ref<\/strong> Document):\n      ...\n<strong>class<\/strong> Scanner:\n   scan -&gt; doc: <strong>ref<\/strong> Document:\n      ...\n<strong>class<\/strong> MultiFunctionPrinter:\n   thePrinter: <strong>obj<\/strong> Printer \n   theScanner: <strong>obj<\/strong> Scanner\n      \n   print(doc: <strong>var<\/strong> Document):\n      thePrinter.print(doc)\n   scan -&gt; doc: <strong>ref<\/strong> Document:\n      doc := theScanner.scan \n   copy:\n      thePrinter.print(theScanner.scan)<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>copy<\/code> method of the composite <code>MutiFunctionPrinter<\/code> uses the properties of the two parts, and it is usually a function that is used directly by a human user. The method <code>print<\/code> is invoked by computers linked to a multi-function printer.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-foreground-color\"> <\/mark>The <code>scan<\/code>-method is typically used by a human who places a document in the scanner and activate the scanner, which sends the scanned document to an email address or to a computer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition to the well-known notation for composition above, it may in some cases be an advantage to see the obj data-items that represent the parts of the composite object. The following figure shows this for both a class and for an object of that class.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"733\" height=\"216\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/MFprinterComposition-6.jpg\" alt=\"\" class=\"wp-image-10536\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/MFprinterComposition-6.jpg 733w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/MFprinterComposition-6-300x88.jpg 300w\" sizes=\"(max-width: 733px) 100vw, 733px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Representing a position on earth<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A position on earth is defined using latitude and longitude, which both are coordinates from -90 to 90 or shown as 0-90 followed by North\/South and East\/West. These coordinates may be further spilt into minutes and seconds &#8211; often abbreviated <em>DMS<\/em> standing for degrees, minus and seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We may represent these values using composition of value objects as follows:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>GlobalPosition: Value\n  la: <strong>var<\/strong> Latitude\n  lo: <strong>var<\/strong> Longitude<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A latitude and longitude may be represented by :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Latitude: Value\n  theDms: <strong>var<\/strong> DMS\n  theDirection: <strong>var<\/strong> NorthSouth\nLongitude: Value\n  theDms: <strong>var<\/strong> DMS\n  direction: <strong>var<\/strong> EastWest <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And finally a <code>DMS<\/code> may be represented by:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DMS: Value\n  degree: <strong>var<\/strong> float\n  min: <strong><strong>var<\/strong><\/strong> Time.Minutes\n  sec: <strong><strong>var<\/strong><\/strong> Time.Seconds<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\">\n<p class=\"wp-block-paragraph\">The figure illustrates the composition hierarchy of a <code>GlobalPosition<\/code>-class:<\/p>\n\n\n\n<figure class=\"wp-block-image alignright size-full\"><img decoding=\"async\" width=\"322\" height=\"501\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/image-3.png\" alt=\"\" class=\"wp-image-7148\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/image-3.png 322w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/image-3-193x300.png 193w\" sizes=\"(max-width: 322px) 100vw, 322px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Note that <code>min<\/code> and <code>sec<\/code> are defined using units of dimension <code>Time<\/code> as described in section <script>mkRef(\"Dimensions and units\")<\/script>. The variable <code>degree<\/code> has no unit. We leave the definition of <code>NorthSouth<\/code> and <code>EastWest<\/code> to the reader.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A model of a university<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The next example shows part of a representation of a university with the purpose of representing the educations given by the university. A university consists of a number of faculties. Each faculty consist of a number of departments.  In this model, a university offers the degrees bachelor, masters and PhD. This structure may be represented in the following way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> University:\n   <strong>class<\/strong> Faculty:\n      ...\n   <strong>class<\/strong> Department:\n      ... \n   <strong>class<\/strong> Degree:\n      ...\n   <strong>class<\/strong> Bachelor: Degree\n      ...\n   <strong>class<\/strong> Masters: Degree\n      ...\n   <strong>class<\/strong> PhD: Degree \n      ...\n   arts: <strong>obj<\/strong> Faculty\n      ...\n   naturalScience: <strong>obj<\/strong> Faculty\n      computerScience: <strong>obj<\/strong> Department\n         bachelorInCS: <strong>obj<\/strong> Bachelor \n            ProgrammingLab: <strong>obj<\/strong> ... \n            ...\n         mastersInCS: <strong>obj<\/strong> Masters\n            ...\n         ...\n      physics: <strong>obj<\/strong> Department\n         bachelorInPhysics: <strong>obj<\/strong> Bachelor\n            ...\n         ...\n   ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the faculties Arts, and Natural Science, etc. are represented by singular objects being subclassed from <code>Faculty<\/code>. Each faculty has departments belonging to the faculty. Within each department there are objects representing the degrees (bachelor, masters, PhD) offered by the department.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The above example is quite sketchy and we leave to the reader to fill it out to a complete example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Representing composition<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In section <script>mkRef(\"Representing classification hierarchies\");<\/script>, we discussed classification as a fundamental means for organizing and understanding phenomena and concepts. <em>Composition<\/em> is another fundamental means for organizing and understanding phenomena. Composition is a means to organize phenomena in terms of other phenomena.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In many situations it is useful to consider a&nbsp;<em>whole<\/em>&nbsp;as constructed from&nbsp;<em>parts<\/em>. The parts may again consist of smaller, simpler parts i.e. there is a distinction between whole phenomena and their <em>parts<\/em>\/phenomena. The notion of a&nbsp;<em>whole\/part composition<\/em>&nbsp;is an important means of understanding and organizing complex phenomena.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <em>part-of relation<\/em> gives rise to a&nbsp;<em>whole\/part hierarchy<\/em>.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\"> <\/mark>The above figure shows an example of such a hierarchy for the <code>MFprinter<\/code> consisting of parts like <code>Printer<\/code>, and <code>Scanner<\/code>. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A car may be considered as consisting of parts like steering wheel, motor, body and wheels, i.e. wheel is a <em>part of <\/em>a car, a motor is a part of a car, etc. These components are physical parts of the car. We may represent a car as shown below.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Car: \n   aSteeringWheel: <strong>obj<\/strong> SteeringWheel \n   aMotor: <strong>obj<\/strong> Motor\n   aBody: <strong>obj<\/strong> Body\n   wheels: <strong>obj<\/strong> Array(4, #Wheel)<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"627\" height=\"186\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/carComposite-2.jpg\" alt=\"\" class=\"wp-image-10506\" style=\"width:539px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/carComposite-2.jpg 627w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/carComposite-2-300x89.jpg 300w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">There are numerous other examples of whole\/part hierarchies:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A tree may be viewed as consisting of branches, a trunk, roots and leaves.<\/li>\n\n\n\n<li>A Hotel Reservation may be viewed as a composition of a Person, a Hotel, a Room and a Date. It is, however, not meaningful to view, for instance, the person as a physical part of the hotel reservation. The corresponding attribute is better viewed as a&nbsp;reference&nbsp;to a person.<\/li>\n\n\n\n<li>A Person may naturally be viewed as consisting of parts like Head, Body, Arms and Legs. In turn, the Legs consist of Lower leg, Foot, etc.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">We define composition in the following way:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To&nbsp;<em>compose<\/em>&nbsp;is to form a compound phenomenon by means of a number of component phenomena. Properties in the intension of the compound phenomenon are described using the component phenomena. The extension of the compound phenomenon consists of phenomena which have components belonging to the extension of the component phenomena.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To&nbsp;<em>decompose<\/em>&nbsp;is to identify a component phenomenon of a phenomenon. Decomposition is the inverse of composition.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Composition gives rise to the&nbsp;following&nbsp;relations:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<em>component-of<\/em>&nbsp;relation is a relationship between a phenomenon and one of its component phenomena.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<em>part-of&nbsp;relation <\/em>is a relation between a phenomenon and one of its part phenomena.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Composition of activities<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It is not just physical phenomena as shown in the above examples that may be organised in terms of wholes and parts. This is also the case for activities. An activity described by a method may consist of other activities. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A activity of making a pizza may be understood as a composition of several sub-activities, including: making the dough, making the tomato sauce, preparing the topping, etc. Like an activity may consist of sub-activities, a computation may consist of sub-computations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As an example from the bank domain, we have that a transfer activity consists of a withdraw activity followed by a deposit activity. This is represented by the transfer method, which is describes a composition of a withdraw computation followed by a deposit computation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/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=3092\" 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 the this chapter, we show how to define composite objects. A composite object consists of other objects. For material objects, we use intrinsic objects (declared using the keyword obj (section )) to represent possible parts. We will use the term part object for an intrinsic object that represents a part of a composite object. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":21,"menu_order":17,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3092","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\/3092","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3092"}],"version-history":[{"count":129,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/3092\/revisions"}],"predecessor-version":[{"id":11290,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/3092\/revisions\/11290"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/21"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}