{"id":9351,"date":"2024-11-11T09:38:11","date_gmt":"2024-11-11T08:38:11","guid":{"rendered":"https:\/\/oopm.org\/?page_id=9351"},"modified":"2024-12-15T11:26:05","modified_gmt":"2024-12-15T10:26:05","slug":"4-1-class-set","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=9351","title":{"rendered":"4.1 Class Set"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages9351&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=wpv2pages9351&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 collection is a set, which is an object that may hold a set of objects. The <code>Set<\/code> collection is defined as follows:<\/p>\n\n\n\n<pre id=\"4.1-class-Set\" class=\"wp-block-code\"><code><strong>class<\/strong> Set(<strong>class<\/strong> ElmType:&lt; Object): \n   insert(e: <strong>ref<\/strong> ElmType): :::\n   has(e: <strong>ref<\/strong> ElmType): :::\n   remove(e: <strong>ref<\/strong> ElmType): :::\n   :::<\/code><\/pre>\n\n\n\n<style>\n#note6-0 {\n  width: 35%;\n  padding-left: 15px;\n  margin-left: 15px;\n  float: right;\n  background-color: lightgray;\n  font-size: 0.8em;\n}\n<\/style>\n<p id=\"note6-0\">The description of class Set as shown here is a simplified description of the class. In a later chapter, we show a more complete description of the Set class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>Set<\/code> has a parameter, <code>ElmtType<\/code>, which is a class name. The <code>ElmType<\/code> parameter specifies the type of the elements that may be inserted into the <code>Set<\/code>. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>Set<\/code> has three methods, <code>insert<\/code>, <code>has<\/code> and <code>remove<\/code>, each having a parameter <code>e<\/code> being a reference to an object of type <code>ElmType<\/code> &#8211; the class parameter of class <code>Set<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note! We have not specified the details of the three methods &#8212; the colons (:::) represents the details not shown. The three methods actually define what is called the <em>interface<\/em> of class <code>Set<\/code> &#8212; the interface of a class (or object) are the attributes (here methods) that may be used to access the attributes of a given instance of the class. The details are often referred to as the <em>implementation<\/em> of the class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is a fundamental principle of programming to define classes and objects and only expose their interfaces. The advantage of this is that as long as the interface of a given class is not changed, it is possible to change the implementation of the class without affecting the use of the class,<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\"> <\/mark>which may appear in many places in the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We may use class <code>Set<\/code> to represent our <code>Account<\/code>-file in the following way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>theAccountsFile: <strong>obj<\/strong> Set(Account)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We may insert a new account into <code>theAccountsFile<\/code> as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aCustomer: <strong>ref<\/strong> Customer\nanAccount: <strong>ref<\/strong> Account\naCustomer:= Customer(\"Linda Berry\",\"England\",\"linda@google.com\")\nanAccount := Account(aCustomer)\ntheAccountsFile.insert(anAccount)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We do not need the two variables <code>aCustomer<\/code>, and <code>anAccount<\/code>, since we may inline the expressions for <code>Customer<\/code> and <code>Account<\/code> in the <code>insert<\/code> expression as in:<\/p>\n\n\n\n<pre class=\"wp-block-code has-tiny-font-size\"><code>theAccountsFile.insert(\n   Account( \n      Customer(\"Linda Berry\",\"England\",\"linda@google.com\")))<\/code><\/pre>\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=9351\" 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 collection is a set, which is an object that may hold a set of objects. The Set collection is defined as follows: The description of class Set as shown here is a simplified description of the class. In a later chapter, we show a more complete description of the Set class. Class Set has [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":469,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-9351","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\/9351","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=9351"}],"version-history":[{"count":8,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/9351\/revisions"}],"predecessor-version":[{"id":10446,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/9351\/revisions\/10446"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/469"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}