principles:tell_don_t_ask_information_expert
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:tell_don_t_ask_information_expert [2020-10-12 16:39] – old revision restored (2013-09-06 15:10) 159.69.186.191 | principles:tell_don_t_ask_information_expert [2021-09-02 12:51] – old revision restored (2021-05-11 22:31) 65.21.179.175 | ||
---|---|---|---|
Line 11: | Line 11: | ||
/* fill in contexts here: */ | /* fill in contexts here: */ | ||
* [[contexts: | * [[contexts: | ||
- | * [[contexts: | + | |
===== Principle Statement ===== | ===== Principle Statement ===== | ||
- | * Assign a responsibility to that [[glossary: | + | Assign a responsibility to this [[glossary: |
- | * Don't ask an object for information, | + | |
===== Description ===== | ===== Description ===== | ||
- | Each module has a set of responsibilities so there is a kind of mapping between | + | Each module has a set of responsibilities. Subsystems have specific tasks, packages group several related classes, classes have methods and attributes, and so on. So there is a kind of mapping between |
- | Another view on the principle is that responsibility mapping is bad when one module has to ask another module for information (getter invocation), | ||
- | The following reasoning shows that //Tell don't Ask// and // | ||
- | |||
- | * Suppose TdA is adhered to, but IE is neglected. | ||
- | * When IE is neglected, then there is a module which is not the information expert for its responsibility. | ||
- | * But then the module has to ask for the information it needs, so TdA is also neglected. | ||
- | * As this violates the assumption that TdA is adhered to, this means that adhering to TdA also results in adhering to IE. | ||
- | * Suppose IE is adhered to but TdA is neglected | ||
- | * When TdA is neglected, then there is a module '' | ||
- | * But then '' | ||
- | * As this violates the assumption that IE is adhered to, this means that adhering to IE also results in adhering to TdA. | ||
- | * So TdA and IE are equivalent views on the same principle. | ||
- | |||
- | Despite of its proof-like form this is not a formal proof as there is no formal definition of TdA and IE. Nevertheless TdA and IE can be seen as two views on the same principle. | ||
===== Rationale ===== | ===== Rationale ===== | ||
- | When this principle is not adhered to, then a module has a responsibility for which it is lacking some information. So in order to fulfill the task the module has to first acquire the needed information by invoking other modules. This increases the dependencies between the modules (which may lead to [[glossary: | + | When this principle is not adhered to, then a module has a responsibility for which it is lacking some information. So in order to fulfill the task the module has to first acquire the needed information by invoking other modules. This increases the dependencies between the modules (which may lead to[[glossary: |
===== Strategies ===== | ===== Strategies ===== | ||
- | * Assign a responsibility to the class that has the largest subset of the needed information. | + | |
- | * Mirror functionality of composed objects to the interface of the class instead of having a getter-method returning the composed object | + | |
- | * Have the objects operate on their own data using appropriate methods. Avoid getters and setters. | + | |
===== Caveats ===== | ===== Caveats ===== | ||
Line 61: | Line 45: | ||
===== Evidence ===== | ===== Evidence ===== | ||
/* Comment out what is not applicable and explain the rest: */ | /* Comment out what is not applicable and explain the rest: */ | ||
- | + | /* | |
- | /* * [[wiki: | + | * [[wiki: |
- | /* * [[wiki: | + | * [[wiki: |
- | + | | |
- | [[wiki: | + | * [[wiki: |
- | + | */ | |
- | /* * [[wiki: | + | |
===== Relations to Other Principles ===== | ===== Relations to Other Principles ===== | ||
Line 83: | Line 65: | ||
* [[Low Coupling]] Adhering to IE typically leads to low coupling as there is less need to communicate with other modules to get the necessary information. But in some cases IE also increases coupling (see [[# | * [[Low Coupling]] Adhering to IE typically leads to low coupling as there is less need to communicate with other modules to get the necessary information. But in some cases IE also increases coupling (see [[# | ||
- | * [[High Cohesion]] Adhering to IE typically leads to high cohesion as responsibilities which belong together typically operate on the same data. But in some cases IE also lowers cohesion (see [[# | + | * [[High Cohesion]] Adhering to IE typically leads to high cohesion as responsibilities which belong together typically operate on the same data. But in some cases IE also lowers cohesion (see [[# |
* [[Model Principle]] (MP): TdA/IE tells how to distribute functionality among the natural classes which are created according to the Model Principle. | * [[Model Principle]] (MP): TdA/IE tells how to distribute functionality among the natural classes which are created according to the Model Principle. | ||
* [[Information Hiding/ | * [[Information Hiding/ | ||
- | * [[Principle of Separate Understandability]] (PSU): TdA/IE is about responsibility assignment. Another aspect of this task is treated by PSU. | ||
==== Principle Collections ==== | ==== Principle Collections ==== | ||
Line 94: | Line 75: | ||
- | ===== Examples | + | ===== Example |
===== Description Status ===== | ===== Description Status ===== | ||
/* Choose one of the following and comment out the rest: */ | /* Choose one of the following and comment out the rest: */ | ||
- | /*[[wiki: | + | [[wiki: |
- | [[wiki: | + | /*[[wiki: |
/ | / | ||
Line 109: | Line 90: | ||
* Andrew Hunt and David Thomas: // | * Andrew Hunt and David Thomas: // | ||
- | ===== Discussion ===== | ||
- | |||
- | Discuss this wiki article and the principle on the corresponding [[talk: |
principles/tell_don_t_ask_information_expert.txt · Last modified: 2021-10-18 21:42 by christian