{"id":10459,"date":"2024-12-15T12:16:59","date_gmt":"2024-12-15T11:16:59","guid":{"rendered":"https:\/\/oopm.org\/?page_id=10459"},"modified":"2024-12-28T06:51:11","modified_gmt":"2024-12-28T05:51:11","slug":"14-2-information-hiding-and-encapsulation","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=10459","title":{"rendered":"14.2 Information hiding and encapsulation"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages10459&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=wpv2pages10459&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\">As mentioned, access modifiers may be use to separate representative parts of a program from non-representative parts. The term <em>information hiding<\/em> is often used for a similar purpose. Information hiding is a software design principle that is used to limit accessibility of attributes in a program component.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The term <em>component<\/em> is a general term used for such program elements &#8211; in this book a component corresponds to an object-descriptor. The term <em>client<\/em> is often use for components that use a given component.  We use the terms component and client below, but a component is as mentioned an object-descriptor, that may define a module, class or singular object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The primary goal of information hiding is to prevent extensive modification to clients whenever the implementation details of a component are changed. This is done by hiding implementation details that are not relevant for the use of a given component.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The term <em>encapsulation<\/em> is often used in connection to information hiding. One may think of information hiding is a design principle and encapsulation as a technical term. A component like a class is said to <em>encapsulate<\/em> attributes and hiding implementation details. A component hides information by encapsulating the information into a component which presents an interface<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The term <em>interface<\/em> of a component is another important term in software design. The interface of a component is the set of attributes that are accessible by clients of the component. The attributes of a given component defined as <code>%public<\/code> thus constitutes the interface of the component. Clients of the interface of a component will access the component purely through its interface. This way, if the implementation changes, the clients do not have to change.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The term <em>Application Programming Interface <\/em>(API) is another common term. It refers to the interface of a component, but is most often used for software modules and\/programs used by other modules or programs, but technically it is an interface.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In many schools of software design, it is a common design principle that the interface of a component should be restricted to a set of methods. Data-items are primarily considered implementation details and access to data-items should therefore be limited. In object-oriented design as advocated in this book, an interface may also include local classes and\/or intrinsic objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Information hiding, encapsulation and interface are technical terms of software design. They go hand inland with programming as modeling. One way of practicing information hiding s to make sure that only representative parts of a module are visible to clients and thus provides the interface. Non-representative parts correspond to implementation. Modules, classes and object-descriptors are language mechanisms for supporting encapsulation supplemented by access modifiers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Information hiding serves as a criterion that can be used to&nbsp;decompose a program into modules. The principle is also useful for reducing&nbsp;coupling&nbsp;within a system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A common use of information hiding is to hide the physical storage layout for data so that if it is changed, the change is restricted to a small subset of the total program. For example, if a three-dimensional point (<em>x<\/em>,&nbsp;<em>y<\/em>,&nbsp;<em>z<\/em>) is represented in a program with three&nbsp;floating-point&nbsp;scalar&nbsp;variables and later, the representation is changed to a single&nbsp;array&nbsp;variable of size three, a module designed with information hiding in mind would protect the remainder of the program from such a change.<\/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=10459\" 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>As mentioned, access modifiers may be use to separate representative parts of a program from non-representative parts. The term information hiding is often used for a similar purpose. Information hiding is a software design principle that is used to limit accessibility of attributes in a program component. The term component is a general term used [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2250,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-10459","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\/10459","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=10459"}],"version-history":[{"count":6,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/10459\/revisions"}],"predecessor-version":[{"id":10796,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/10459\/revisions\/10796"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/2250"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}