In computer programming:
Coupling and Cohesion are two contrasting terms in computer programming. Coupling is the degree in which each module inside of a larger program relies on each of the other modules inside the same program. Cohesion relates to the degree in which each module is independent and how similar its functions are. Low coupling often correlates with high cohesion, and high coupling often correlates with low cohesion. Low coupling is a goal of a programmer because low coupling is a sign of a well-structured system with good design. When a program has high coupling, it is more difficult to make any changes to individual modules. The more modules rely on each other, the harder it is to go in and make changes to one module without affecting the rest of the modules. Utilizing the top-down design method would be pointless if programmers did not strive for low coupling in their programs. When a program has high cohesion, code readability is increased, complexity is kept manageable, and the ability and likelihood of reusing code is greatly increased.
There are many types of coupling and cohesion and they all have different levels of desirability. The most desirable types of coupling are data coupling, message coupling or no coupling at all because they have the lowest level of coupling. The most desirable types of cohesion are communicational cohesion, sequential cohesion, and functional cohesion because they have the highest level of cohesion. Coupling also takes place between different levels of modules. Subclass coupling is the description of the relationship between a parent module and its child module, where the child is connected to the parent but the parent is not connected to the child.
In the real world:
Just like top-down design, cohesion and coupling can be related to many things in the real world. I will compare the concepts of coupling and cohesion to running a restaurant and how each entity interacts with each other. To keep it simple, instead of talking about every person that works at said restaurant, I will just be discussing groups of employees such as servers, bussers, cooks, chefs, and managers. Just as in programming, a restaurant desires an employee that can do his job on his own (low coupling or high cohesion), the restaurant runs well when employees can do their job without constantly needing help from others. Although the ideal employee may be self sufficient, there are times when interaction between employees is necessary. Examples of this could be when a server asks a busser to help refill waters, or when a server orders his table’s food with the kitchen, or how a chef times the cooking of entrees on the grill with the grill cook and the sides with the line cook. All of these would be examples of coupling in the restaurant business. Just as there are different levels of coupling and cohesion in programming, the same applies to a restaurant and its employees. The examples I just gave would rank from low coupling first to high coupling last. The manager couples with all other employees, so the manager’s level of coupling is high because of all the different employees that they interact with and they many different ways that they interact.
No comments:
Post a Comment