Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Modular Design
Laws and Principles
in OOP and FP
Cohesion
Coupling
Cohesion
Coupling
1972
?
● Coincidental Cohesion: unrelated elements
● Temporal Cohesion: operations performed at the same time, e.g. initializatio...
● Content Coupling: a module uses/alters data in another module
● Global-data Coupling: two modules communicate via global...
A modular unit of code...
● serves a clear purpose
● easy to use
● easy to extend
● easy to replace
● survives outside cha...
Elements inside a package...
● are used together
● change together
Common Reuse Principle
Common Closure Principle
Packages should...
● be as stable as they are abstract
● depend on more stable packages
● not have cycles
Stable Abstracti...
The Law of Demeter
"the principle of least knowledge"
A
B
E G
F
D
C
B
E
The Demeter
Project
Train Wreck
client.getMortgage().paymentCollection().getNextPayment().applyPayment(300.0)
(update-in client [:mortgage :pa...
Tell don’t ask
Feature Envy
in conclusion
Nächste SlideShare
Wird geladen in …5
×

Modular Design - Laws and Principles - in OOP and FP

270 Aufrufe

Veröffentlicht am

Applying the laws and principles of modular design, like cohesion and coupling, to Object-oriented and Functional Programming

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

Modular Design - Laws and Principles - in OOP and FP

  1. 1. Modular Design Laws and Principles in OOP and FP
  2. 2. Cohesion Coupling
  3. 3. Cohesion Coupling 1972 ?
  4. 4. ● Coincidental Cohesion: unrelated elements ● Temporal Cohesion: operations performed at the same time, e.g. initialization ● Sequential Cohesion: operations form a pipeline - one's output is another's input ● Informational Cohesion: operations are performed on the same data structure ● Functional Cohesion: all elements realize a single, well-defined task, e.g. a function Cohesion levels
  5. 5. ● Content Coupling: a module uses/alters data in another module ● Global-data Coupling: two modules communicate via global data ● Data-structure Coupling: communicate via data structure passed as a parameter (more information than needed) ● Data Coupling: communicate via parameter passing (minimal information) ● No Coupling: independent modules Coupling levels
  6. 6. A modular unit of code... ● serves a clear purpose ● easy to use ● easy to extend ● easy to replace ● survives outside changes Single Responsibility Liskov Substitution Interface Segregation Open-Closed Principle Dependency Inversion
  7. 7. Elements inside a package... ● are used together ● change together Common Reuse Principle Common Closure Principle
  8. 8. Packages should... ● be as stable as they are abstract ● depend on more stable packages ● not have cycles Stable Abstractions Principle Stable Dependencies Principle Acyclic Dependencies Principle
  9. 9. The Law of Demeter "the principle of least knowledge" A B E G F D C B E
  10. 10. The Demeter Project
  11. 11. Train Wreck client.getMortgage().paymentCollection().getNextPayment().applyPayment(300.0) (update-in client [:mortgage :payments] conj (payment 300.0)) wiki.c2.com/?TrainWreck
  12. 12. Tell don’t ask Feature Envy
  13. 13. in conclusion

×