{"id":2479,"date":"2023-12-20T13:01:50","date_gmt":"2023-12-20T12:01:50","guid":{"rendered":"https:\/\/oopm.org\/?page_id=2479"},"modified":"2024-12-30T10:02:12","modified_gmt":"2024-12-30T09:02:12","slug":"4c-1-class-details","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=2479","title":{"rendered":"7.1 Class details"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages2479&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=wpv2pages2479&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\">A class is a template for objects with identical structure, and has the form:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> <em>ClassName<\/em>(<em>Parameter<\/em>s): <em>SuperClass<\/em>\n   <em>Declarations<\/em>\n   <em>Statements<\/em><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A class has a name as specified by&nbsp;<em><code>ClassName<\/code><\/em>.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A class may have parameters as specified by&nbsp;<em><code>Parameters<\/code><\/em>&nbsp;\u2013 if no parameters, the brackets are not needed. The&nbsp;<em><code>Parameters<\/code><\/em>&nbsp;may be one or more declarations of data-items or virtual methods and classes. Virtual methods and classes as parameters are explained in&nbsp;chapter <script>mkRef(\"Virtual classes\");<\/script>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A class may have a superclass as specified by&nbsp;<em><code>SuperClass<\/code><\/em>. We explain superclass in chapter <script>mkRef(\"Subclasses and submethods\");<\/script>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The body of a class consists of a sequence of possible declarations and statements as specified by&nbsp;<em><code>Declarations<\/code><\/em>&nbsp;and&nbsp;<em><code>Statements<\/code><\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Class instantiation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We have seen two ways of creating objects from a class as shown here:<\/p>\n\n\n\n<pre class=\"wp-block-code has-tiny-font-size\"><code>JohnSmithsAccount: <strong>obj<\/strong> Account(JohnSmithsProfile)\nanAccount: <strong>ref<\/strong> Account\nanAccount := Account(LindaBerrysProfile)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We have explained the difference between using <code><strong>obj<\/strong><\/code> and <strong><code>ref<\/code><\/strong> in sections <script>mkRef(\"Introducing a Customer class\")<\/script> and <script>mkRef(\"Reference data-items\")<\/script>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The declaration:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>JohnSmithsAccount: <strong>obj<\/strong> Account(JohnSmithsProfile)<\/code>, <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">and the statement:&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>anAccount := Account(LindaBerrysProfile)<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">both include an expression <code>Account(...)<\/code>. This expression creates an&nbsp;<code>Account<\/code>-object with actual parameters&nbsp;<code>(...)<\/code> &#8211; either <code>JohnSmithsProfile<\/code> or <code>LindaBerrysProfile<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The evaluation of the expression returns a reference to the newly created <code>Account<\/code>-object. In <code>JohnSmithsAccount: <strong>obj<\/strong> Account(JohnSmithsProfile)<\/code>, <code>JohnSmithsAccount<\/code> is holding this reference.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the statement <code>anAccount := Account(LindaBerrysProfile)<\/code>, this reference is assigned to <code>anAccount<\/code>.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Execution of the expression&nbsp;<code>Account(...)<\/code> also implies that first the declarations in <code>Account<\/code> are <em>generated<\/em> and second the statements in <code>Account<\/code> are <em>executed<\/em>.&nbsp;Note that even if declarations and statements may be mixed, the declarations are allocated before the statements are executed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The object&nbsp;<code>X<\/code>&nbsp;executing<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-foreground-color\">&nbsp;<\/mark><code>Account(...)<\/code>&nbsp;is called the&nbsp;invoker<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\"> <\/mark>and the&nbsp;<code>Account<\/code>-object being generated is called the&nbsp;<em><span style=\"caret-color: rgb(172, 44, 44);\">invoke<\/span>e<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Instantiation of a singular object<\/em>&nbsp;takes place in the same way as instantiation of a class, except that there are no actual parameters.<\/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=2479\" 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>A class is a template for objects with identical structure, and has the form: A class has a name as specified by&nbsp;ClassName.&nbsp; A class may have parameters as specified by&nbsp;Parameters&nbsp;\u2013 if no parameters, the brackets are not needed. The&nbsp;Parameters&nbsp;may be one or more declarations of data-items or virtual methods and classes. Virtual methods and classes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2338,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2479","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\/2479","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=2479"}],"version-history":[{"count":49,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/2479\/revisions"}],"predecessor-version":[{"id":10845,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/2479\/revisions\/10845"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/2338"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}