Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Cohesion (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== High cohesion == {{refimprove section|date=May 2023}} In [[object-oriented programming]], a class is said to have high cohesion if the methods that serve the class are similar in many aspects.<ref name="Marsic_2012"/> In a highly cohesive system, code readability and [[reusability]] is increased, while complexity is kept manageable. [[File:CouplingVsCohesion.svg|thumb|Cohesion]] Cohesion is increased if: *The functionalities embedded in a class, accessed through its methods, have much in common. *Methods carry out a small number of related activities, by ''avoiding'' [[Granularity#Data granularity|coarsely grained]] or unrelated sets of data. *Related methods are in the same source file or otherwise grouped together; for example, in separate files but in the same sub-directory/folder. Advantages of high cohesion (or "strong cohesion") are: *Reduced module complexity, with fewer operations. *Increased system [[maintainability]], because logical changes in the domain affect fewer modules, and changes in one module require fewer changes in other modules. *Increased module reusability, because application developers will find the [[Software component|component]] they need more easily among the cohesive set of operations provided by the module. While in principle a module can have perfect cohesion by only consisting of a single, atomic element β having a single function, for example β in practice complex tasks are not expressible by a single, simple element. Thus a single-element module has an element that is either too complicated to accomplish a task, or too narrow and thus tightly [[Coupling (computer programming)|coupled]] to other modules. Thus cohesion is balanced with both unit complexity and coupling.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)