What Is Cohesion And Coupling In Software Engineering
Categories: Software Engineering
What Is Cohesion And Coupling In Software Engineering?
Software engineering is the systemized application of engineering principles to develop software. It includes not just writing code, but all of the tools and processes or methods an organization uses in building and maintaining that code over time. Front-end software engineering involves engineering software that meets the visual ends of the application or system. Back-end software engineering is where engineers make parts of the applications and systems that clients and administrators use.
Software design can be divided into three separate levels - interface design, architectural design, and detailed design. Software design is about defining the architecture, components, interfaces, and other characteristics of a system or component. The design stage of the SDLC provides solutions to problems in the SRS Document (System Requirement Specification).
Moreover, designing is an iterative process categorized into two parts-
Conceptual design- It is demonstrated in easy language with a detailed explanation of system characteristics and description of the functions of the system that explains the system used to customers and ;
Technical design- Allows the developers to address and solve customer’s problems with a detailed understanding of hardware components and design, functions and stages of software development, the flow and structure of data, and network architecture.
Both the terms cohesion and coupling are an integral part of programming terminology. They have frequently used terms mainly to describe the independence or interdependence of modules and their relative strengths. To know the meaning of cohesion and coupling, you can use this as your guide. This article is curated to help you thoroughly understand the importance of the two terms.
What is Coupling?
Coupling measures how closely two software modules are connected and the extent of their interdependence. It measures the strength of the relationships between several modules. Two tightly coupled modules strongly depend on one another. However, loosely coupled are independent of each other. Moreover, modules that are uncoupled have no interdependence at all. Coupling has many types, but usually, low coupling is suitable for software.
The classification of the different coupling types helps to estimate the degree of coupling between two modules quantitatively. Each type of coupling comes with its own set of features, with benefits as well as disadvantages. The following are the different types of coupling in the order of highest to lowest coupling-
Content Coupling: It is the worst form of coupling and should be avoided. It exists amongst two modules if they share code, e.g., a branch from one module into another module. This includes a module amending the data of another module or control flow being passed from a module to the other module.
Common Coupling: Two modules accessing the same global data structure if they share data. Disadvantages include uncontrolled error propagation, complexity to reuse modules, reduced ability to control data accesses, and reduced maintainability.
External couplings: These couplings are related to communication to external tools and devices, which occurs when two modules have to share data in an externally imposed format, communication protocol, or device interface.
Control coupling: This coupling exists between two modules when data from one module directs the order of instructions to be executed in another module. In simpler terms, one module controls the flow of another by passing information on what to do. Flag set in different modules is an example of control coupling.
Stamp coupling: This occurs when several modules share complete composite data items and use different parts of them like PASCAL or a structure in C. For example, passing structure variables in C or objects in C language to a module.
Data coupling: Two modules are coupled if they communicate by passing only data. For example, an elementary data item is passed as a parameter between two modules. The components are independent of each other.
What is Cohesion?
The qualitative measure of how strongly the elements are related functionally inside a module is called cohesion in software engineering. It is an ordinal measurement generally described as "high cohesion" or "low cohesion." Cohesion is the extent to which the parts of a module are functionally related. It is the extent to which all parts directed to perform a single task are contained. It is basically the strength of the relationships within the modules.
The different cohesion types, from the worst to the best, are as follows:
Coincidental cohesion: In this type of cohesion, the parts of a module are grouped arbitrarily. Therefore, the elements have no relationship other than the location in the source code. Examples include a module for miscellaneous functions, customer record usage, displaying customer records, calculating total sales, reading the transaction record, etc.
Logical cohesion: A module is logically cohesive if all module elements perform similar operations. Examples of activities of the same category or of the general category contributed by the components in the module include a report module, display module, or input-output module.
Temporal cohesion: When a module includes functions associated with the fact that you must execute all the methods simultaneously, the module is said to demonstrate temporal cohesion. Therefore, multiple activities occur simultaneously at a unit time.
Procedural cohesion: In this, parts of a module that follow a particular execution sequence are grouped. Some examples of procedural cohesion are read, write, edit the module, record use out, writing out the record, reading the record, zero paddings to the numeric fields, returning records, etc.
Communicational/Informational cohesion: In this, parts of a module that operate on the same data items are grouped, e.g., the set of functions defined on an array or a stack.
Sequential cohesion: In this type, components in a module are grouped in a sequence as the output from one component becomes the input of another component. Examples include cross-validate record and formatting of a module, raw records usage, formatting of raw records, cross-validation of fields in raw records, returning of formatted cross-validated records.
Functional cohesion: The unique feature is that it only performs the necessary activities making it strong, focused, and ideal cohesion. In this type, components in a module are grouped because they all contribute to a single well-defined module task. Examples include read transaction records, cosine angle computation, seat assignment to an airline passenger, etc.
Difference between Cohesion and Coupling
In simple terms, Cohesion means keeping together while Coupling means joining together. While coupling deals with the interdependence of modules, cohesion deals with the module itself. A module with the best cohesion and weak coupling is an ideal one.
Conclusion
Today, this field is considered a vast and emerging one for a person to grow and make their career in. There are many institutes that are providing online software engineering courses. With the advent of technology, the software developer field is growing in both salary and job volume. Upskill yourself and enhance your career in this field by taking up Great Learning Courses.