User Tools

Site Tools


principles:model_principle

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
principles:model_principle [2018-12-08 10:24] – [Rationale] christianprinciples:model_principle [2018-12-08 10:43] – [Description Status] christian
Line 33: Line 33:
 When the structures in the software roughly correspond to the structures of the problem domain, a developer doesn't have to learn both of them. Knowing the problem domain is inevitably necessary. Any further structure of the software has to be learned and understood in addition. So creating a direct mapping between them, makes understanding the software easier, which improves maintainability. In such a system for most functionality there is a "natural", i.e. an intuitively clear place to implement it. This makes structuring the software easier and helps finding the implementation for a given functionality. When the structures in the software roughly correspond to the structures of the problem domain, a developer doesn't have to learn both of them. Knowing the problem domain is inevitably necessary. Any further structure of the software has to be learned and understood in addition. So creating a direct mapping between them, makes understanding the software easier, which improves maintainability. In such a system for most functionality there is a "natural", i.e. an intuitively clear place to implement it. This makes structuring the software easier and helps finding the implementation for a given functionality.
  
-Moreover if something works accidentally, it breaks accidentally. In the example above supplying a ''Product'' to the ''cancelOrder'' method only works because by some circumstance it is made sure that  when ''cancelOrder'' is called, there is only one order for that particular product. It's a hidden precondition. As the software is changed, this hidden precondition may not be guaranteed anymore. This results in a non-obvious bug in a part of the system you haven't directly touched. Similarly in the ''deleteOrder'' example: The ''cancelOrder'' operation might get enhanced by creating a reverse invoice, a credit note, or a message to the customer. But an order might have to be deleted for purely technical reasons (migration to a new order system, etc.). So if you call ''cancelOrder'' instead of ''deleteOrder'' this will produce nasty bugs if ''cancelOrder'' gets enhanced as described.+Moreover if something works accidentally, it breaks accidentally. Many many bugs are created because you are not precise with semantics. 
 + 
 +In the example above supplying a ''Product'' to the ''cancelOrder'' method only works because by some circumstance it is made sure that  when ''cancelOrder'' is called, there is only one order for that particular product. It's a hidden precondition. As the software is changed, this hidden precondition may not be guaranteed anymore. This results in a non-obvious bug in a part of the system you haven't directly touched. Similarly in the ''deleteOrder'' example: The ''cancelOrder'' operation might get enhanced by creating a reverse invoice, a credit note, or a message to the customer. But an order might have to be deleted for purely technical reasons (migration to a new order system, etc.). So if you call ''cancelOrder'' instead of ''deleteOrder'' this will produce nasty bugs if ''cancelOrder'' gets enhanced as described. 
 ===== Strategies ===== ===== Strategies =====
  
Line 39: Line 41:
   * Create methods corresponding to real-world actions   * Create methods corresponding to real-world actions
   * Map additionally necessary behavior to natural classes instead of creating artificial classes   * Map additionally necessary behavior to natural classes instead of creating artificial classes
-  * For artificial behavior that cannot be mapped to a natural class at least create a metaphor or an artificial model (like for example a state machine) +  * For artificial behavior that cannot be mapped to a natural class at least create a metaphor or an artificial model (like a state machine) 
 +  * Be precise with semantics. If you have an operation that currently does what you need but for slightly different reasons because it's an operation on the wrong abstraction level, create a new operation with the correct semantics. Have that new operation call the existing one as an implementation detail (e.g. have a ''cancelOrder'' method call the ''deleteOrder'' method).
  
 ===== Caveats ===== ===== Caveats =====
Line 117: Line 119:
 /* Choose one of the following and comment out the rest: */ /* Choose one of the following and comment out the rest: */
 /*[[wiki:Stub]]*/ /*[[wiki:Stub]]*/
-[[wiki:Incomplete]] +/*[[wiki:Incomplete]]*
-/*[[wiki:Complete]]*/+[[wiki:Complete]]
  
  
principles/model_principle.txt · Last modified: 2021-10-18 21:47 by christian