Skip to content

OOP Principles

ehzan edited this page Jan 23, 2023 · 4 revisions

Object-Oriented Programming Principles

Cohesion Over Coupling Principle [*]

Cohesion refers to the degree to which the elements inside a module belong together, usually contrasted with coupling, which is the degree of interdependence between software modules. Modules with high cohesion and loose coupling tend to be preferable in computer programming. Prefer cohesion over coupling!

cohesion-vs-coupling.png

Composition Over Inheritance Principle [*]

The "composition over inheritance" principle in object-oriented programming is the principle that classes should achieve code reuse through their composition (by containing instances of other classes that implement the desired functionality) rather than inheritance from a base or parent class.



coc. https://en.wikipedia.org/wiki/Cohesion_(computer_science)
coi. https://en.wikipedia.org/wiki/Composition_over_inheritance