{"id":7412,"date":"2024-09-11T08:18:02","date_gmt":"2024-09-11T06:18:02","guid":{"rendered":"https:\/\/oopm.org\/?page_id=7412"},"modified":"2025-01-14T14:43:59","modified_gmt":"2025-01-14T13:43:59","slug":"5-5-value-assignment-and-comparison","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=7412","title":{"rendered":"5.5 Value assignment and comparison"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages7412&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=wpv2pages7412&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 section <script>mkRef(\"Reference data-items\");<\/script>, we have described assignment and comparison for references. In summary, we may assign a reference <code>r2<\/code> to <code>r1<\/code> (<code>r1 := r2<\/code>): <code>r1<\/code> then refers to the same object as <code>r2<\/code>. We do not copy the content of the object referred by <code>r2<\/code> to the object referred by <code>r1<\/code>. Two different reference data items may refer to the same object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly for a comparison, <code>r1 = r2<\/code> is true if <code>r1<\/code> and<code> r2<\/code> refer to the same object &#8211; and <code>r1 &lt;&gt; r2<\/code> is true if they refer to different objects. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For primitive value types the situation is different. Value objects are just needed for representing values &#8211; it is the content of a value object that is important and not the value object itself. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>v1<\/code> and <code>v2<\/code> are different data-items of type <code>float<\/code>, we may assign <code>v2<\/code> to <code>v1<\/code> (<code>v1 := v2<\/code>) and the value hold by <code>v2<\/code> is now also hold by <code>v1<\/code>. It is <em>not<\/em> the case that <code>v1<\/code> and <code>v2<\/code> refer to the same value object.<br>The same applies to comparison, the comparison <code>v1 = v2<\/code> is true if <code>v1<\/code> and <code>v2<\/code> represent the same value. This is illustrated by the following example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>v1,v2: <strong>var<\/strong> float\nb: var Boolean\nv1 := 3.14\nv2 := 7.5\nb := v1 = v2  -- now b = false since v1 and v2 represent different values\nb := v1 &lt;&gt; v2 -- now b = true\nv2 := v1      -- now v1 and v2 represent the same value, 3.14\nb := v1 = v2  -- now b = true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>v1<\/code> and <code>v2<\/code> are two different value objects of the same type, assignment <code>v1 := v2<\/code> implies that the local data-items in <code>v2<\/code> is copied to the corresponding data-items in <code>v1<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a comparison <code>v1 = v2<\/code>, is true if the local data-items of <code>v1<\/code> are equal to the corresponding local data-items of <code>v2<\/code>. If the local data-item is a compound value, this applies recursively.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We want assignment and companions for value objects in general to work as for primitive value types. Two value objects of type <code>Point<\/code> may represent the same point or different points, and this must be reflected in assignment and comparison. Consider the following example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Point(x,y: <strong>var<\/strong> Integer): Value\n   ...<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\">\n<\/mark>\np1, p2: <strong>var<\/strong> Point\nb: <strong>var<\/strong> Boolean\np1 := Point(10,11)\np2 := Point(20,21)\nb := p1 = p2      -- now b = false since p1 and p2 represent different points \nb := p1 &lt;&gt; p2     -- now b = true\np2 := p1          -- now p1 and p2 represent the same point(10,11)\nb := p1 = p2      -- now b = true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The next list of snapshots illustrates the effect of assignment and comparisons on value objects:<\/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:60%\">\n<p class=\"wp-block-paragraph\">The first snapshot shows the situation after <code>b := p1 = p2<\/code> &#8211; marked by a red arrow.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The assignment <code>p1 := Point(10,11) <\/code>has been executed;<\/li>\n\n\n\n<li>the value of <code>p1<\/code> is <code>p1.x = 10<\/code> and <code>p1.y = 11<\/code>;<\/li>\n\n\n\n<li><code>p2 := Point(20,21) <\/code>has been executed;<\/li>\n\n\n\n<li>the value of <code>p2<\/code> is thus  <code>p2.x = 20<\/code> and <code>p2.y = 21<\/code>;<\/li>\n\n\n\n<li><code>b := p1 = p2<\/code> has been executed;\n<ul class=\"wp-block-list\">\n<li>this includes evaluation of the comparison <code>p1 = p2<\/code> evaluation to <code>false<\/code>;<\/li>\n\n\n\n<li>the value of <code>b<\/code> is thus <code>false<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"548\" height=\"322\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-1-1.jpg\" alt=\"\" class=\"wp-image-10524\" style=\"width:400px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-1-1.jpg 548w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-1-1-300x176.jpg 300w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/><\/figure>\n<\/div>\n<\/div>\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:60%\">\n<p class=\"wp-block-paragraph\">This snapshot shows the situation after the assignment <code>b := b1 &lt;&gt; b2<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This includes evaluation of the comparison <code>b1 &lt;&gt; b2<\/code> evaluating to <code>true<\/code>;<\/li>\n\n\n\n<li>the value of <code>b<\/code> is thus now <code>true<\/code><\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"566\" height=\"322\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-2.jpg\" alt=\"\" class=\"wp-image-10525\" style=\"width:397px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-2.jpg 566w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-2-300x171.jpg 300w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/figure>\n<\/div>\n<\/div>\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:100%\">\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:100%\">\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:60%\">\n<p class=\"wp-block-paragraph\">This snapshot shows the immediately before execution of the assignment <code>p2 := p1<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Execution of <code>p2 := p1<\/code> corresponds to executing the assignments:\n<ul class=\"wp-block-list\">\n<li><code>p2.x := p1.x<\/code><\/li>\n\n\n\n<li><code>p2.y := p1.y<\/code> <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"747\" height=\"490\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-3.jpg\" alt=\"\" class=\"wp-image-10526\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-3.jpg 747w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-3-300x197.jpg 300w\" sizes=\"(max-width: 747px) 100vw, 747px\" \/><\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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:60%\">\n<p class=\"wp-block-paragraph\">This snapshot then shows the situation after execution of the assignment <code>p2 := p1<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The value of <code>p2<\/code> is now <code>p2.x = 10<\/code> and <code>p2.y = 11<\/code>;<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"574\" height=\"340\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-4.jpg\" alt=\"\" class=\"wp-image-10527\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-4.jpg 574w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-4-300x178.jpg 300w\" sizes=\"(max-width: 574px) 100vw, 574px\" \/><\/figure>\n<\/div>\n<\/div>\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:60%\">\n<p class=\"wp-block-paragraph\">The final snapshot shows the situation after the assignment <code>b := p1 = p2<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The right side of the assignment is a comparison <code>p1 = p2<\/code> that values to <code>true<\/code>;<\/li>\n\n\n\n<li>the value of <code>b<\/code> is now <code>true<\/code>.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"581\" height=\"340\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-5.jpg\" alt=\"\" class=\"wp-image-10528\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-5.jpg 581w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/PointAssignment-5-300x176.jpg 300w\" sizes=\"(max-width: 581px) 100vw, 581px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Here we have a more elaborated example. We define class <code>Line<\/code> as a value object with data-items of type <code>Point<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Line(p1,p2: <strong>var<\/strong> Point): Value\n   ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The following snapshots of object <code>geometricEx<\/code> illustrates the effect assignment of <code>Line<\/code> objects. The first snapshot shows the situation after <code>line1 := Line(Point(1,2), Point(3,4))<\/code> has been executed. As can be seen, <code>line1.p1.x = 1<\/code>, <code>line1.p1.y = 2<\/code>, <code>line1.p2.x = <\/code>3, and <code>line1.p2.y = 4<\/code>.<\/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:60%\">\n<pre class=\"wp-block-code\"><code> geometricEx: <strong>obj<\/strong>\n    line1,line2: <strong>var<\/strong> Line\n    line1 := Line(Point(1,2), Point(3,4))\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\">--&gt; <\/mark>line2 := line1<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"278\" height=\"426\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/geometricEx-1-3.jpg\" alt=\"\" class=\"wp-image-8640\" style=\"width:248px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/geometricEx-1-3.jpg 278w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/geometricEx-1-3-196x300.jpg 196w\" sizes=\"(max-width: 278px) 100vw, 278px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The next snapshot shows the situation after the assignment <code>line2 := line1<\/code>. The assignment implies that the local data-items of <code><code>line1<\/code><\/code> is copied to the corresponding data-items of <code><code>line<\/code>2<\/code>. Since the local data-items are composite values of type <code>Point<\/code>, the copying is recursive in the sense that the local data items of the <code>Point<\/code> objects are copied to the corresponding <code>Point<\/code> objects in <code>line2<\/code>. As can be seen, <code>line2.p1.x<\/code>, etc. now all have the values as the corresponding variables in <code>line1<\/code>:<\/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:60%\">\n<pre class=\"wp-block-code\"><code> geometricEx: <strong>obj<\/strong>\n    line1,line2: <strong>var<\/strong> Line\n    line1 := Line(Point(1,2), Point(3,4))\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\">    <\/mark>line2 := line1\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\">--&gt;<\/mark><\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:40%\">\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"416\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/geometricEx-2-2.jpg\" alt=\"\" class=\"wp-image-8641\" style=\"width:238px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/geometricEx-2-2.jpg 258w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/geometricEx-2-2-186x300.jpg 186w\" sizes=\"(max-width: 258px) 100vw, 258px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Value parameter transfer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Invocation of a method like <code>anAccount.deposit(500)<\/code> involves the transfer of the argument 500 to the parameter <code>amount<\/code> of the <code>deposit<\/code> object generated as part of the invocation &#8211; this is called <em>parameter transfer<\/em>. Parameter transfer is similar to assignment in the sense that the argument 500 is assigned to the parameter <code>amount<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In a similar way generation of an object like <code>Point(2,3)<\/code> implies that the arguments 2 and 3 are <em>assigned<\/em> to the parameters <code>x<\/code> and <code>y<\/code> of the generated <code>Point<\/code> object as described above.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The generation of a <code>Line<\/code> object as in <code>Line(Point(1,2), Point(3,4))<\/code> involves generation of two <code>Point<\/code> objects where the arguments 1, 2 and 3, 4 are assigned to the <code>x<\/code> and <code>y<\/code> parameters of the two new <code>Point<\/code> objects and these <code>Point<\/code> objects are then subsequently assigned to the <code>p1<\/code> and <code>p2<\/code> parameters of the new <code>Line<\/code> object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next we illustrate parameter transfer for a <code>Line<\/code> object. We use a method that computes the intersection of two lines as an example although we leave the computation as an exercise<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\">.<\/mark> For simplicity, we assume there is an intersection point between the two lines.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>intersect(l1,l2: <strong>var<\/strong> Line) -&gt; p: <strong>var<\/strong> Point: \n   p := ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Below we have extended <code>geometricEx<\/code> and the first snapshot shows the situation <em>during<\/em> the execution of <code>intersectingPoint := intersect(line1, line2)<\/code> and at the start of the invocation of <code>intersect<\/code> (marked by red) at the point where a method object with default values has been generated:<\/p>\n\n\n\n<div class=\"wp-block-media-text has-media-on-the-right is-stacked-on-mobile\" style=\"grid-template-columns:auto 18%\"><div class=\"wp-block-media-text__content\">\n<pre class=\"wp-block-code\"><code> geometrixEx: obj\n    line1, line2: <strong>var<\/strong> Line\n    line1 := Line(Point(1,2), Point(3,4)) \n    line2 := Line(Point(5,6), Point(7,8))\n    intersectingPoint: <strong>var<\/strong> Point\n    ...\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\">--&gt;<\/mark> intersectingPoint := intersect(line1, line2)<\/code><\/pre>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"194\" height=\"383\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/intersect-1.jpg\" alt=\"\" class=\"wp-image-10419 size-full\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/intersect-1.jpg 194w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/intersect-1-152x300.jpg 152w\" sizes=\"(max-width: 194px) 100vw, 194px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">After the intersect method object has been generated the arguments <code>line1<\/code> and <code>line2<\/code> are passed to the method object. This involves two assignments <code>intersect.l1 := line1<\/code> and <code>intersect.l2 := line2<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The assignment <code>intersect.l1 := line1<\/code> implies that the local data-items of <code><code>line1<\/code><\/code> is copied to the corresponding data-items of <code><code>l<\/code><\/code>1 in the <code>intersect<\/code> method object. Since the local data-items are composite values of type <code>Point<\/code>, the copying is recursive in the sense that the local data items of the <code>Point<\/code> objects are copied to the corresponding <code>Point<\/code> objects in <code>l<\/code>1. Similarly for the second argument <code>line2<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next snapshot shows the <code>geometricEx<\/code> object and the <code>intersect<\/code> method object after the arguments have been transferred &#8211; for simplicity only <code>line1<\/code> and <code>l1<\/code> are shown:<\/p>\n\n\n\n<div class=\"wp-block-media-text has-media-on-the-right is-stacked-on-mobile is-vertically-aligned-center\" style=\"grid-template-columns:auto 20%\"><div class=\"wp-block-media-text__content\">\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"278\" height=\"426\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/geometricEx-1-4.jpg\" alt=\"\" class=\"wp-image-8642\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/geometricEx-1-4.jpg 278w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/geometricEx-1-4-196x300.jpg 196w\" sizes=\"(max-width: 278px) 100vw, 278px\" \/><\/figure>\n<\/div><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"196\" height=\"382\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/intersect-2-1.jpg\" alt=\"\" class=\"wp-image-10422 size-full\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/intersect-2-1.jpg 196w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/intersect-2-1-154x300.jpg 154w\" sizes=\"(max-width: 196px) 100vw, 196px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Aliasing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As a consequence of the above rules for assignment it is not possible to have two or<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\"> <\/mark>more names that denote the same value object as is the case for objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The fact that you can denote the same object with two or more names is called <em>aliasing<\/em>. Aliasing may complicate programming since the state of an object may be modified from different places in a program &#8211; the programmer therefore has to be careful when using references. As we argue below, we need aliasing for objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, we do not want aliasing when dealing with values since this does not make sense and may easily lead to unexpected results. It is thus not possible to have two or more names denoting the same value object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the following example, we illustrate the difference between data items representing values and data items representing references with respect to aliasing. First we consider value objects:<\/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<ul class=\"wp-block-list\">\n<li>After the assignment <code>p2 := p1<\/code>, <code>p2 = Point(1,2)<\/code>. <\/li>\n\n\n\n<li>After the assignment <code>p1 := Point(3,4)<\/code>, <code>p1 = Point(3,4)<\/code>, and <code>p2<\/code> is unaffected and we still have <code>p2 = Point(1,2)<\/code>.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>p1,p2: var Point\np1 := Point(1,2)\np2 := p1\np1 := Point(3,4)\n-- <span style=\"background-color: initial; font-family: inherit; font-size: inherit; color: var(--wp--preset--color--primary);\">p2 = Point(1,2)<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The next example illustrates arising for references:<\/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<ul class=\"wp-block-list\">\n<li>After the assignment <code>acc2 := acc1<\/code>, <code>acc1<\/code> and <code>acc2<\/code> refer to the same <code>Account<\/code> object.<\/li>\n\n\n\n<li>After the assignment <code>acc1.balance := 250<\/code>, we also have <code>acc2.balance = 250<\/code>, since <code>acc2<\/code> refers to the same object as <code>acc1<\/code>.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>acc1, acc2: <strong>ref<\/strong> Account\nacc1.balance := 150\nacc2 := acc1\nacc1.balance := 250\n-- <span style=\"background-color: initial; font-family: inherit; font-size: inherit; color: var(--wp--preset--color--primary);\">acc2.balance = 250<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Rationale <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As mentioned in section <script>mkRef(\"On representing phenomena\"); <\/script>, we distinguish phenomena representing physical entities local accounts, vehicles, customers, etc. and properties of physical entities like balance of an account, length of a vehicle and the name of a customer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Objects represent physical entities and we may have several references to a given object. A given vehicle may be referred to from a vehicle registration system, an insurance company, the owner of the vehicle, etc. We thus want to be able to represent having several references to the same object in our computerized models. Assignment and comparison of references are thus about references and not the state (data-items) of the objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The properties of physical entities are often represented by values of some type and as said above, from a modeling point of view, it is the values that are relevant and not the value objects holding the values.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is in contrast to objects representing physical entities &#8211; here the objects are relevant with respect to modeling. The state of a given object with respect to the datums hold by its data items are of course also important.<\/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=7412\" 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 section , we have described assignment and comparison for references. In summary, we may assign a reference r2 to r1 (r1 := r2): r1 then refers to the same object as r2. We do not copy the content of the object referred by r2 to the object referred by r1. Two different reference data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2270,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-7412","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\/7412","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=7412"}],"version-history":[{"count":55,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/7412\/revisions"}],"predecessor-version":[{"id":11137,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/7412\/revisions\/11137"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/2270"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}