{"id":420,"date":"2023-05-14T13:32:29","date_gmt":"2023-05-14T11:32:29","guid":{"rendered":"https:\/\/oopm.org\/?page_id=420"},"modified":"2024-12-19T10:11:53","modified_gmt":"2024-12-19T09:11:53","slug":"2-3-how-to-generate-an-object","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=420","title":{"rendered":"2.3 The first object"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages420&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=wpv2pages420&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<style>\ncode{\n     font-size: 0.85em;\n}\n<\/style>\n\n\n\n<p class=\"wp-block-paragraph\">In order to generate objects&nbsp;as part of a model&nbsp;in the computer, we must describe the objects in a language that can instruct the computer to generate the objects. As mentioned, such a language is called a programming language.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below we show the&nbsp;<em>description<\/em>&nbsp;of an object representing the account of John Smith: <\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code>account_1010: <strong>obj<\/strong>\n   owner: <strong>val<\/strong> \"John Smith\"\n   balance: <strong>var<\/strong> float <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The keyword&nbsp;<code><strong>obj<\/strong><\/code>&nbsp;specifies that the program element is a description of an object. The name of the object is&nbsp;<code>account_1010<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The object has two <em>attributes<\/em> characterizing the account:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The owner of the account is represented by the data-item&nbsp;<code>owner<\/code>&nbsp;holding the&nbsp;<em>string value<\/em>&nbsp;<code>\"John Smith\"<\/code>. A string value (also called&nbsp;<em>string literal)<\/em>&nbsp;is a sequence of characters enclosed in double quotes (<code>\"<\/code>).&nbsp;<\/li>\n\n\n\n<li>The balance of the account is represented by the data-item&nbsp;<code>balance<\/code>&nbsp;that may hold the value of a&nbsp;<em>real<\/em>&nbsp;number. A real number may be a number with a decimal point as 350.56. The variable&nbsp;<code>balance<\/code>&nbsp;may hold this number. For this example we assume that the balance is in Euro. If balance holds the value 350.56, this means that balance is 350.56 Euro.&nbsp;<\/li>\n<\/ul>\n\n\n\n<style>\n#XXX {\n  width: 30%;\n  padding-left: 15px;\n  margin-left: 15px;\n  float: right;\n  background-color: lightgray;\n  font-size: 0.85em;\n}\n<\/style>\n<div id=\"XXX\">Note!  A computer can only represent a subset of real numbers. This subset is often called\u00a0<i>floating point numbers<\/i> and\u00a0<code>float<\/code>\u00a0is used as the type instead of\u00a0real\u00a0in many programming languages.<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The names&nbsp;<code>String<\/code>&nbsp;and&nbsp;<code>float<\/code>&nbsp;are examples of&nbsp;<em>types<\/em>. A type defines the set of values that a given data-item may hold. The data-item&nbsp;<code>owner<\/code>&nbsp;is said to be of type&nbsp;<code>String<\/code>&nbsp;since it may only hold <code>String<\/code> values. Similarly the data-item&nbsp;<code>balance<\/code>&nbsp;is said to be of type&nbsp;<code>float<\/code> since it may only hold real numbers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The keyword&nbsp;<code><strong>val<\/strong><\/code>&nbsp;is a shorthand for value and specifies that the data-item holds a value that is constant as long as the object exists. The keyword&nbsp;<strong><code>var<\/code><\/strong>&nbsp;is a shorthand for variable and specifies that the data-time may hold different values during the life-time of the object. We return to this in chapter <script>mkRef(\"Data items\");<\/script>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As said above, the code\/program fragment above is a description of an object \u2014 it is not the object itself as represented in the computer.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We may give this description to a compiler, which translates it into machine language. We may then execute the resulting machine language, which will generate the object in the computer.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We use the term <em>object-descriptor<\/em> or simply <em>descriptor<\/em> for the text describing the attributes of the object. For <code>account_1010<\/code>, the attributes are the two data-items <code>owner<\/code> and <code>balance<\/code>. <\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"504\" height=\"154\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/DescriptorOf1010.jpg\" alt=\"\" class=\"wp-image-7219\" style=\"width:401px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/DescriptorOf1010.jpg 504w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/08\/DescriptorOf1010-300x92.jpg 300w\" sizes=\"(max-width: 504px) 100vw, 504px\" \/><figcaption class=\"wp-element-caption\">object-descriptor of account_1010<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As we shall see later, an object-descriptor may include other elements than data-items.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The description of John Smiths account is made in a programming language called qBeta. As mentioned, a programming language is a formal notation for instructing a computer. The elements of a program&nbsp;are&nbsp;phrases that may describe declarations, objects, data-items, statements to be executed and combinations&nbsp;of&nbsp;these. The description of <code>account_1010<\/code> is an example of a declaration of a data-item &#8211; in this case an object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A description written in a programming language is called a <em>computer program<\/em> or just a <em>program<\/em>, but is also referred to as <em>source code<\/em> or simply <em>code<\/em>. A collection of programs is often referred as <em>software<\/em>. The description of the above object is thus an example of a program although it is not very useful. <\/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=420\" 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 order to generate objects&nbsp;as part of a model&nbsp;in the computer, we must describe the objects in a language that can instruct the computer to generate the objects. As mentioned, such a language is called a programming language. Below we show the&nbsp;description&nbsp;of an object representing the account of John Smith: The keyword&nbsp;obj&nbsp;specifies that the program [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":175,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-420","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\/420","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=420"}],"version-history":[{"count":61,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/420\/revisions"}],"predecessor-version":[{"id":10625,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/420\/revisions\/10625"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/175"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}