principles:information_hiding_encapsulation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
principles:information_hiding_encapsulation [2021-02-02 02:52] – old revision restored (2020-12-10 16:42) 95.216.157.202 | principles:information_hiding_encapsulation [2021-03-24 20:02] – old revision restored (2021-02-01 19:42) 188.34.165.240 | ||
---|---|---|---|
Line 19: | 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 '' | ||
- | * Otherwise use immutable objects which are handled call-by-reference but needn' | ||
- | * Avoid aliasing problems with lists and similar data structures | ||
- | * Copy internal list objects before returning them or only return a read-only '' | ||
- | |||
- | ===== Caveats ===== | ||
- | |||
- | See section [[#contrary principles]]. | ||
Line 61: | Line 47: | ||
* [[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. | * [[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. | ||
* [[Liskov Substitution Principle]] (LSP): For subclasses you can waken encapsulation by having a wider '' | * [[Liskov Substitution Principle]] (LSP): For subclasses you can waken encapsulation by having a wider '' | ||
- | * [[Tell, don't Ask/ | + | |
- | * [[Low Coupling]] (LC): Higher forms of couplings (especially content couplings) break encapsulation. | + | |
- | * [[Principle of Separate Understandability]] (PSU): | + | * [[Low Coupling]] (LC): |
- | * [[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. | + | * [[Principle of Separate Understandability]] (PSU): |
==== Principle Collections ==== | ==== Principle Collections ==== | ||
Line 72: | Line 58: | ||
- | ===== Examples | + | ===== Example |
principles/information_hiding_encapsulation.txt · Last modified: 2021-10-18 21:56 by christian