External Coupling?-?Types Of?Coupling
Ahmed Samir Ahmed
Senior Android Software Engineer @IDH | Ex E-Finance fintech | Android | IOS | Dotnet
Table of?contents
1- Coupling in Object-Oriented Programming
Coupling can be described as the degree of interdependence between various subroutines or modules within a software program. Coupling increases when two classes become more connected, either because one class includes an attribute referencing the second class or when the first class inherits from the second class. Tight coupling arises when objects from one class are called by another class. On the other hand, loose coupling signifies a linkage (connection) where one module interacts with another module through a consistent interface, and the internal implementation of one module do not need to impact (need not be affected) the other modules significantly. In this case, there is a minimal level of reliance (a smaller amount of interdependence) between the two subroutines and a limited exchange of information.
2. Definition
It is described as the interdependency between two or more modules that use a shared format, external files, or communication protocol as shown in figure 1.
3. Overview
3.1 Introduction
In software development, the modularization process is typically employed, which involves dividing an entire system into small modules that works independently to design complex software in a good way. Coupling is a software metric that measures the level of interdependency among different modules within a system. It is preferable to have low coupling for good software. We have various forms (types) of coupling include: Data coupling, Stamp coupling, Control coupling, External coupling, Common coupling, and Content coupling. Data coupling is typically regarded as the most favorable, while content coupling is seen as the least desirable. In external coupling, modules are dependent on each other by sharing a common external data format, device interface, or data communication protocols. The interconnection (interdependency) between two modules primarily concerns their interaction with external devices and file formats, rather than (instead of) any shared data structure or common data. External coupling typically occurs when various modules directly interact with infrastructure layers, which encompass (includes) functions associated with the operating system.
3.2 Concept In?details
This coupling occurs when the two or more modules have some common external influencing factors and are interrelated by sharing data between an external module. So, there is a dependency on an external library or system by sharing externally imposed data format, communication protocol, external file or device interface.
In details, these factors can be a:
So, this is basically related to the communication to external tools. It is best to reduce the number of places in the code where such dependencies exist, also creating a layer between your code and this external library may reduce this type of coupling?… the “Facade” and “Repository” patterns may help.
Please note that: Modules are tied to an environment external to software. It is essential but should be limited to small number of module with in a structure. Because changes in the external system can affect the overall implementation and integration of those resources within your software.
4. How to measure the degree of external?coupling
External coupling measures (assesses) the degree to which the system depends (relies) on external entities to achieve (fulfill) its functionality or interact (engage) with the external environment.
Low external coupling?—?When the internal implementation of the system is not or minimally affected by alterations (Changes or Modifications) occur in external entities (e.g. library).
Medium external coupling?—?When changes occur in external entities (e.g. library) then modifications within the system are necessary (required) to accommodate new interfaces. Therefore, it required some changes in the internal system due to the changes that occurred in the external entities (e.g. library).
领英推荐
High external coupling?—?Changes in external entities (e.g. library) result in considerable (huge) impacts on the internal system implementation, demanding (needs to) extensive modifications in the internal system.
5. Properties
6. Examples?
6.1 Theoretical example
External coupling, as implied by its name, pertains (refers) to the interconnection (dependence) of various (multiple) modules concerning (related to) external factors. These common external factors encompass (includes) components such as input-output devices, external files, infrastructure systems, or communication protocols. It involves linking two or more modules to a common part of the external environment outside the software. External coupling belongs to a category of high-level coupling, specifically tight coupling, which is not ideal (undesirable) but probably necessary. Figure 2 illustrates the external coupling among three modules, M1, M2, and M3, as they share a common I/O device, protocol, or data format.
External coupling pertains (is related) to communication with external devices rather than the shared a common data or data flow. Any modification (changes) made by one module to an external file or a communication protocol will definitely have an impact on other modules. These changes can be seen as beneficial for all other modules, but they can also a problematic for the other modules. Let’s say the modules in information system development all use a common file format for reading and storing files, but if one module requires a different file format, it can create issues for the other modules. To prevent conflicts, it’s recommended to maintain a low level of external coupling between the modules.
6.2 Example?code
It’s like something we have to put up with, even if we don’t like it. External coupling occurs when our system requires assistance (needs help from an outside) from external sources like third-party libraries or systems. Given the frequency of such occurrences, it becomes crucial to have a deep understanding of this concept. Employing design patterns is a strategic approach we can try to reduce the occurrence of (adopt to minimize the presence) of external dependencies within our systems. One effective strategy is to introduce intermediary layers between our code and external libraries (by creating layers between libraries and our code ‘our system’). Among the various technical solutions available, the “Facade ”and “Repository ”patterns (most popular technical solutions) stand out as the most widely recognized methods for managing (limiting) or even preventing the storage of external libraries within our codebase.
However, it’s quite difficult (It is rather impossible) to eliminate external coupling. It’s not easy to completely avoid them. Therefore, the external coupling should not be seen as a major threat (risk) to our code.
7. References
?? Cheers???
?I’m also available for discussing anything related to Android, so if you’d like to chat, feel free to reach out to me on LinkedIn.???
?If you are interested in more articles on my Medium account, you can use this?Link. I hope that you’re having a great day.???
??Don’t forget to give a star or leave a comment if you found it useful.??