User Tools

Site Tools


principles:information_hiding_encapsulation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
principles:information_hiding_encapsulation [2021-02-02 18:58] – old revision restored (2020-12-10 07:39) 95.216.157.202principles:information_hiding_encapsulation [2021-03-20 13:12] – old revision restored (2021-02-02 18:56) 159.69.189.215
Line 1: Line 1:
-====== Information Hiding/Encapsulation (IH/E) ======+====== Information Hiding/Encapsulation ======
  
 ===== Variants and Alternative Names ===== ===== Variants and Alternative Names =====
- 
-  * Parnas' Law((Anbert Endres, Dieter Rombach: //A Handbook of Software and Systems Engineering//)) 
  
  
Line 21: Line 19:
  
 ===== Strategies ===== ===== Strategies =====
- 
-  * Use the lowest possible visibility for a variable or method 
-    * Make all attributes private and use getter and setter methods to access them 
-    * Better also avoid getters and setters 
-    * Find suitable abstractions for data types and use appropriate methods instead of just getters and setters 
-  * Avoid aliasing problems with value objects 
-    * If the programming language supports that use call-by-value objects (like stack objects in C++, structs in C#, records in Delphi, etc.) for value objects like ''Date'', ''Money'', ''EMailAddress'', ''TelephoneNumber'', etc.  
-    * Otherwise use immutable objects which are handled call-by-reference but needn't be copied 
-  * Avoid aliasing problems with lists and similar data structures 
-    * Copy internal list objects before returning them or only return a read-only ''interface'' to them 
- 
- 
-===== Caveats ===== 
- 
-See section [[#contrary principles]]. 
  
  
 ===== Origin ===== ===== Origin =====
- 
-David Parnas: //On the Criteria To Be Used in Decomposing Systems into Modules// 
  
  
Line 51: Line 32:
   * [[wiki:Questioned]]   * [[wiki:Questioned]]
 */ */
- 
  
 ===== Relations to Other Principles ===== ===== Relations to Other Principles =====
Line 61: Line 41:
 ==== Contrary Principles ==== ==== Contrary Principles ====
  
-  * [[Keep It Simple Stupid]] (KISS): Not adhering to IH/E is often easier.+  * [[principles:Keep It Simple Stupid]]
  
 ==== Complementary Principles ==== ==== Complementary Principles ====
  
-  * [[Model Principle]] (MP): IH/E demands having an interface for a module which hides the inner workings. MP tells how such an interface can look like. +  * [[principles:Model Principle]] 
-  * [[Liskov Substitution Principle]] (LSP)For subclasses you can waken encapsulation by having a wider ''protected'' interface which can be used by subclasses. For these cases LSP has to be considered, too. +  * [[principles:Liskov Substitution Principle]] 
-  * [[Tell, don't Ask/Information Expert]] (TdA/IE): Encapsulation is about not having getter methods returning constituent internal parts of a module. TdA can be another reason for that. +  * [[principles:Invariant Avoidance Principle]] 
-  * [[Low Coupling]] (LC): Higher forms of couplings (especially content couplings) break encapsulation. +  * [[principles:Information Expert]] 
-  * [[Principle of Separate Understandability]] (PSU): IH/E is about constructing a module in a way that hides the inner workings so it can be used without knowing them. PSU on the other hand is about constructing a module such that its inner workings (and its usage also) can be understood without knowledge about //other// modules. +  * [[principles:Low Coupling]] 
-  * [[Easy to Use and Hard to Misuse]] (EUHM): A module should be properly encapsulated in order to make it easy to use and hard to misuse. +  * [[principles:Principle of Separate Upderstandability]]
  
 ==== Principle Collections ==== ==== Principle Collections ====
Line 79: Line 58:
  
  
-===== Examples =====+===== Example =====
  
  
Line 87: Line 66:
 /*[[wiki:Incomplete]]*/ /*[[wiki:Incomplete]]*/
 /*[[wiki:Complete]]*/ /*[[wiki:Complete]]*/
- 
  
 ===== Further Reading ===== ===== Further Reading =====
  
-  * [[wiki>EncapsulationDefinition]] 
-  * [[wp>Encapsulation (object-oriented programming)]] 
- 
-  * [[wiki>InformationHiding]] 
-  * [[wp>Information hiding]] 
- 
-  * [[http://www.javaworld.com/javaworld/jw-05-2001/jw-0518-encapsulation.html|Java World: Encapsulation is not information hiding]] 
-  * [[wiki>EncapsulationIsNotInformationHiding]] 
  
-  * [[wiki>OnDecomposingSystems]] 
principles/information_hiding_encapsulation.txt · Last modified: 2021-10-18 21:56 by christian