Our main topic for this series is how to write good software with this quote
Good software is highly cohesive and loosely coupled (Separation Of Concern).
Writing maintainable, testable and readable code helps increase productivity for us as developers. Having highly maintainable code makes it easier to design new features and write code. Modular, component-based, and layered code increase productivity and reduce risk and cost when making changes.
In software design, it is the degree to which the elements of a certain class belong together.
The elements within the object are directly related to the functionality the object is meant to provide. By keeping high cohesion within our code, we end up trying DRY code and reduce duplication of knowledge in our object. We can easily design, write, and test our code since all the code for our object is located together and works together.
High cohesion gives us better designed code that is easier to maintain.
We cannot always make it perfect, but we can at least strive for it.
The point is, while building classes the lesser the elements are, the greater the possibility for reusing them in all the methods.
3- Communicational/informational cohesion: is when parts of a module are grouped because they operate on the same data.
$db->Update(record)
record->Print()
4- Procedural cohesion: is when parts of a module are grouped because they always follow a certain sequence of execution (e.g., a function which checks file permissions and then opens the file).
$userInput->All()
$validator->Validate($userInput)
$db->Store()
5- Temporal cohesion: is when parts of a module are grouped to perform a series of actions related in time (e.g., a function which is called after catching an exception which closes open files, creates an error log, and notifies the user).
6- Logical cohesion: is when parts of a module are grouped because they are logically categorized to do the same thing even though they are different by nature (e.g., grouping all mouse and keyboard input handling routines).
7- Coincidental cohesion (worst): is when parts of a module are grouped arbitrarily; the only relationship between each part is that they have been grouped together (e.g., a “Utilities” class).
Thanks @hedayasamy for your review.