{"id":231,"date":"2023-05-09T11:50:05","date_gmt":"2023-05-09T09:50:05","guid":{"rendered":"https:\/\/oopm.org\/?page_id=231"},"modified":"2024-10-25T11:47:03","modified_gmt":"2024-10-25T09:47:03","slug":"3-classes-2","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=231","title":{"rendered":"3. Classes"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages231&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=wpv2pages231&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 chapter <script>mkRef(\"Objects\");<\/script>, we showed how to represent the account of John Smith as an object. We will of course, also need to represent the accounts of Liza Jones and Mary Pole. To do this we may of course define account objects similar to&nbsp;<code>account_1010<\/code> of John Smith for these accounts. The account of Liza Jones may be e.g. defined as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>account_1022: <strong>obj<\/strong>\n   owner: <strong>val<\/strong> \"Liza Jones\"\n   balance: <strong>var<\/strong> float\n   interestRate: <strong>var<\/strong> float\n   addInterest:\n      balance := balance + (balance * interestRate) \/ 100\n   deposit(amount: <strong>var<\/strong> float):\n      balance := balance + amount\n   withdraw(amount: <strong>var<\/strong> float) -&gt; newB: <strong>var<\/strong> float:\n      balance:= balance - amount\n      newB := balance  <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The description of Liza Jones account is identical to the description of John Smiths account except for the value of&nbsp;<code>owner<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In general, the program should reflect that the accounts of Liza Jones and John Smith are of the same kind\/form &#8211; it should  appear from their descriptions that they both represents accounts. In addition, we should avoid repeating the same code at different places. In the next section, we show how to do that using the class mechanism.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-foreground-color\"> <\/mark> <\/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=231\" 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 chapter , we showed how to represent the account of John Smith as an object. We will of course, also need to represent the accounts of Liza Jones and Mary Pole. To do this we may of course define account objects similar to&nbsp;account_1010 of John Smith for these accounts. The account of Liza Jones [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":21,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-231","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\/231","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=231"}],"version-history":[{"count":35,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/231\/revisions"}],"predecessor-version":[{"id":8802,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/231\/revisions\/8802"}],"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=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}