{"id":2250,"date":"2023-12-14T14:01:40","date_gmt":"2023-12-14T13:01:40","guid":{"rendered":"https:\/\/oopm.org\/?page_id=2250"},"modified":"2025-01-24T11:12:39","modified_gmt":"2025-01-24T10:12:39","slug":"54-visibility-representative-elements-information-hiding","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=2250","title":{"rendered":"14. Representative and non-representative parts"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages2250&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=wpv2pages2250&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 this chapter, we discuss representative and non-representative parts of a program with respect to modeling a given domain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A primary focus of this book has been to emphasize that programming is modeling in the sense that programming is about creating a model of the relevant aspects of the application domain. This implies that one should attempt to represent descriptions of phenomena and their properties by corresponding language elements in the program.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There will, however be elements in a given program that do not relate to phenomena or concepts from the application domain. This is due to the fact that it must be possible to execute the program on a computer. To do this, a program will have elements that implement the elements that relate to the model of the application domain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The part of the program that describes phenomena and concepts from the application domain is called the<em> representative part.<\/em> The part which is  not representative is called <em>non-representative<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"453\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/09\/DomainModelRepresentative-1-1024x453.jpg\" alt=\"\" class=\"wp-image-7446\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/09\/DomainModelRepresentative-1-1024x453.jpg 1024w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/09\/DomainModelRepresentative-1-300x133.jpg 300w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/09\/DomainModelRepresentative-1-768x340.jpg 768w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/09\/DomainModelRepresentative-1.jpg 1199w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Non-representative parts of class <code>Account<\/code><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the following we consider class&nbsp;<code>Account<\/code>&nbsp;in the bank domain with respect to representative and non-representative parts.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img decoding=\"async\" width=\"1077\" height=\"551\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/AccountWithPrivate.jpg\" alt=\"\" class=\"wp-image-8565\" style=\"width:748px;height:auto\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/AccountWithPrivate.jpg 1077w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/AccountWithPrivate-300x153.jpg 300w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/AccountWithPrivate-1024x524.jpg 1024w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/10\/AccountWithPrivate-768x393.jpg 768w\" sizes=\"(max-width: 1077px) 100vw, 1077px\" \/><figcaption class=\"wp-element-caption\">Representation of concepts and phenomena in the bank domain<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the previous versions of&nbsp;<code>Account<\/code>&nbsp;there is at a first glance no attributes that cannot be considered representative. All of <code>owner<\/code>, <code>balance<\/code>, <code>interestRate<\/code>, <code>deposit<\/code>, <code>withdraw<\/code>, etc. are meaningful in the bank domain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We originally introduced assignments like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>account_1010.balance := 523.07<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and said that such an assignment may be considered a deposit on the account. And further assignments like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>account_1010.balance := account_1010.balance + 200\naccount_1010.balance := account_1010.balance - 300<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">may also be considered deposits or withdrawals.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, we have methods\u00a0<code>deposit<\/code>\u00a0and\u00a0<code>withdraw<\/code>, which are supposed to represent deposits and withdrawals of money on the account. And from a\u00a0modeling point of view these conflict with assigning to\u00a0<code>balance<\/code>\u00a0directly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, there is more to a <code>deposit<\/code> and <code>withdraw<\/code> than just updating <code>balance<\/code>. In section <script>mkRef(\"Composite values\")<\/script>, we introduced class <code>Transactions<\/code> and an object <code>transaction<\/code>, which keeps track of deposits and withdrawals on a given account. We would thus want to prevent access to\u00a0<code>balance<\/code>\u00a0from outside the <code>Account<\/code>-objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, we do want to be able to read\/print the current balance of a given account. In addition, we may want to log that someone has read the balance of an account.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We may handle this by adding a method&nbsp;<code>getBalance<\/code>&nbsp;to the class <code>Account<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>getBalance -&gt; bal:&nbsp;<strong>var<\/strong>&nbsp;float: transact\n&nbsp;&nbsp;&nbsp;bal := balance&nbsp;\n&nbsp;&nbsp;&nbsp;theTransaction.what := \u201cgetBalance\u201d<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above considerations also apply to the variable <code>interestRate<\/code>. Here we do not want to be able to manipulate <code>interestRate<\/code> directly from outside an account, as update of an <code>interesRate<\/code> may imply more actions to be carried out. This may include informing the customer about the change.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We may thus introduce a method <code>getInterestRate<\/code> like <code>getBalance<\/code> and we may introduce methods <code>setInterestRate<\/code> and <code>getInterestRate<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the next section we introduce language mechanisms for controlling the accessibility of attributes.<\/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=2250\" 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 this chapter, we discuss representative and non-representative parts of a program with respect to modeling a given domain. A primary focus of this book has been to emphasize that programming is modeling in the sense that programming is about creating a model of the relevant aspects of the application domain. This implies that one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":21,"menu_order":14,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2250","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\/2250","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=2250"}],"version-history":[{"count":128,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/2250\/revisions"}],"predecessor-version":[{"id":11309,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/2250\/revisions\/11309"}],"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=2250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}