Product manager, you don't understand high cohesion and low coupling?

Introduction

When discussing system design with architects, the voices of "high cohesion" and "low coupling" can always be heard everywhere, as if this is a wall between architects and product managers, a gap between primary and advanced. But if you understand their principles, it will not be so magical. You must know that these two words are not dedicated to research and development. As product managers, our understanding of these two words can be even broader than that of architects.

This article starts with a story and ends with another story. I'll talk to you about the high cohesion and low coupling in my eyes. Look down!

Today, I'd like to start with a living story and talk about my own understanding of these two words. I believe you can also discuss with these architects after reading this article. Moreover, the high cohesion and low coupling in the eyes of product managers should not be limited to the system design itself, but also think in the front business direction and do cohesion and decoupling from the business level.

 A Living story

The story begins like this:

Tom, Jason, and Joe are college classmates. After graduating from college, they made an appointment to go to New York together. Since the salary for the first time was relatively low, in order to save the rent, the three of them shared the rent together. They continue the lifestyle of the university dormitory, drinking, bragging, playing games together after get off work every day, singing, playing basket ball and eating together on weekends when there is plenty of time. 

This happy life lasted for three years. The three of them each had girlfriends. Occasionally, when a girlfriend came over, the other two had to go out to avoid embarrassment. It was very inconvenient, so the three rented a large three-bedroom apartment. In a private room, this can not only solve the problem of girlfriends coming to get together, but also the three of them can continue to have fun together. With the improvement of accommodation conditions and the warming up of the love of the young couples, in order to overcome the pain of lovesickness and to maximize the saving of resources, the young couples tried their best to overcome the obstacles and live together, so that the original three people lived in the house. 6 people.

Since three people became three families of six, the original happy days began to change slightly. The reason was that the sound insulation effect of the room was not very good, and the grumpy Tom and his girlfriend always quarreled, which seriously affected Jason and Joe next door. Over time, the girlfriends of the two families became angry. In addition, the three families often conflict over the use of the kitchen and bathroom. The handling of things between girlfriends is no longer as simple and rough as the previous three men. Once they are not handled well, everyone knows the consequences.

Half a year later, in order to prevent the conflict between their girlfriends from further intensifying, Tom, Jason, and Joe finally decided not to renew the lease. The three of them took their girlfriends out to rent a single room, and only got together on weekends when they were free. . In this way, although Tom often quarrelled with his girlfriend and still slept late, all the problems encountered when the three rented together were resolved, and there was no conflict. After the three girlfriends met, they were more cordial than before ...

Distill from the story the backbone we need: high cohesion and low coupling. From the perspective of resource allocation, we analyze why the relationship between three people was very good when they were renting together at the earliest. When they rent together with girl friends, there will be contradictions. Later, when they live separately, the relationship becomes better? Think for three minutes.

What are high cohesion and low coupling?

To put the story aside, let's first understand what cohesion and coupling are.

The so-called cohesion refers to the degree of close connection between the elements within a certain thing. If the same elements are more concentrated, the cohesion is higher, and vice versa. For example, the internal organs in the human body cooperate with each other from birth. If they are replaced by other people's organs, there will be a phenomenon of rejection, which is high cohesion.

The so-called coupling refers to the dependence between different things. If the dependence on each other is stronger, the coupling is higher, and vice versa. Take the human body as an example. The heart is responsible for blood supply, the lungs are responsible for breathing, and the liver is responsible for metabolism. There is a clear division of labor among each other and each performs its own responsibilities. Even if a certain part is sick, it only needs targeted treatment without affecting other parts. This is low coupling. .

After understanding the concept, let's come back and analyze the ending of the story: why did the relationship between the three people at the earliest time was very good, but after the three people shared the lease, there would be conflicts, and then after they lived separately, the relationship improved again?

he answer is revealed: at first, when three people rent together, saving money is the most important. There are few people, good feelings and simple things, so there will be no big contradiction. After becoming three families, they become three different families. Each family has different plans and demands, and saving money is not the first demand. Under the same roof, the family affairs of Lao Chen and his girlfriend will inevitably affect Lao Zhang and Lao Li. In addition, everyone usually shares public resources such as kitchen and bathroom. As long as one family is in use, the other two will be affected. The girlfriends of Lao Chen, Lao Zhang and Lao Li do not have the same deep emotional foundation as the three of them. Over time, contradictions naturally arise.

The answer is revealed: at first, when three people rent together, saving money is the most important. There are few people, good relations and simple things, so there will be no big contradiction. After becoming three families, they become three different families. Each family has different plans and demands, and saving money is not the first demand. Under the same roof, the family affairs of Tom and his girlfriend will inevitably affect Jason and Joe. In addition, everyone usually shares public resources such as kitchen and bathroom. As long as one family is in use, the other two will be affected. The girlfriends of Tom, Jason and Joe do not have the same deep emotional foundation as the three of them. Over time, contradictions naturally arise.

 

 3 Periods

This is the principle of high cohesion and low coupling. At first, when the three people rent together, they have few people, have more emotional foundation, save money first, and there is no problem of cohesion and coupling; When three families and six people rent together, they rely too much on each other, and the actions of any one will affect the other two. The coupling is too high, so it is easy to have problems; After separation, each family is responsible for their own life and no longer depends on others. At the same time, they can only contact each other on weekends, and the coupling is reduced, so the relationship is closer.

Look, is it the same as our system design? When the system is very small, in order to save resources, we share a set of resources together, which is the most efficient. With the gradual increase of the complexity of the system and team and the increasing dependence on each other, there will be frequent resource problems and development bottlenecks. Finally, in order to solve the problem of high coupling, we can only split the system and team, perform their respective duties, and finally evolve into a standard high cohesion and low coupling model.

3. How to achieve high cohesion and low coupling

From the definition, we should be clear that high cohesion and low coupling actually mean two things, one internally (high cohesion) and one externally (low coupling). From the perspective of products, high cohesion and low coupling should not be limited to the level of system design, which will be narrow. The correct interpretation should be based on the two levels of business and system.

Examples of high cohesion and low coupling
 

1. Business level

Whether the division of responsibilities of business departments, the planning and design of processes, or the management of operation sites, all need to follow the principle of high cohesion and low coupling. We should try to centralize the management of the same feature, processes and operations as much as possible, while the responsibilities and boundaries between different features, processes and operations are clear, the communication and cooperation are smooth and do not affect each other, which is specifically reflected in:

(1) Each department and position has a clear division of labor and each performs its own duties. For example, procurement, warehousing and distribution, although there is a lot of overlap, should be different job roles when assigning people and positions.  Even if some companies are small and don't have many posts, it should also be clear that only one person has done multiple posts, rather than integrating multiple functions into one post.

(2) The processes are clear and the responsibilities are single. When designing business processes, the principle of single feature should be considered. Each set of processes solves a core business scenario. Although people and features can be reused in many cases, they should be designed separately at the level of processes and rules, and should not be mixed. For example, sales outbound and return to supplier outbound, although both are outbound, system features and operators can be reused, but the objects of outbound are different and should be regarded as two business processes.

(3) The site management rules and regulations are clear and the flow direction is clear. In the on-site management of storage center and logistics center, it is necessary to plan the reservoir area and product flow direction according to different posts, different commodities and different business forms, and formulate rules and regulations, such as receiving and shipping area management, whole and bulk area management, large and medium-sized area management, so that each process corresponds to different rules, each area is responsible for different storage forms, and each post operates different business documents, They can connect seamlessly without interfering with each other.

2. System level

When doing system design, it is necessary to ensure that the same system and feature modules are as cohesive as possible, and the systems and feature modules are decoupled as much as possible, which is reflected in the following:

  • The features of system and module are single and the boundary is clear. When planning the system, each system and each feature module under each system should have clear responsibilities, and there is only one core responsibility, and there is a clear boundary with other modules to avoid ambiguity. For example, the inventory module is responsible for handling all inventory related matters, and the inbound module is responsible for handling the inbound process. The boundary between the two is the operation of inventory during inbounding, which is triggered by the warehousing module and executed by the inventory module. 

  • Unified data and logic. There should be only one responsible party for each data and logic operation. When other modules need to operate this data, they should be authorized by this module and communicated through interface services, so as to maximize the integrity and security of data and features. For example, both inbound and outbound operations need to operate inventory, but the logic of inventory is handled by the inventory module. Inbound and outbound operations of inventory need to interact through the interface provided by the inventory module, and do not directly hand over the processing of inventory to inbound and outbound.  

  • Interact with as few systems as possible to reduce complexity between systems. Refer to Demeter's Law in Software Design Principles: Talk only to your immediate friends and not to strangers, try to avoid interactions between multiple systems, and form Cartesian product and network structure. For example, there are 3 ERPs on the top, and they all need to interact with the 3 WMS systems below. At this time, you should consider using an intermediate system to undertake 3 ERPs for the top and 3 WMS systems for the bottom. Do not let each The ERP forms a Cartesian product with each WMS separately.

 

Of course, although the design of high cohesion and low coupling looks more reasonable, it still needs to be implemented according to the situation, because the realization of high cohesion and low coupling will definitely bring about an increase in labor costs and system implementation costs, just like the story, after the separation of Tom, Jason and joe's three families, high cohesion and low coupling have indeed been achieved, but everyone needs to rent a house by themselves, and also needs to buy daily necessities and kitchen utensils. The total cost must be higher than It is when sharing a house.

When designing processes and systems, we should make decisions based on the actual situation. There is no need to over-design according to the script. Here, I provides several thinking suggestions:

  • The system design comes from the business. Before doing the cohesion and coupling of the system, first sort it out from the business level to make the business do a good job of high cohesion and low coupling. Many times, the problem is not the system, but the business side does not do a good job of cohesion and decoupling.

  • In the early stage of business development, when the process and system are relatively simple and the future is not yet clear, quick trial and error is required. You don’t need to think too much about cohesion and coupling (just take it into account), first support the business in the lowest cost way, and wait for the business to become clear. It is not too late to continue to adjust in the future. Don't over-design. It is a real waste to undertake the business of 1,000 orders with a scale structure of 100,000 orders.

  • If the business is relatively stable and unchanged for a long time, proper coupling will be more reasonable, such as the basic attributes of commodities, key information of orders, address database information, etc. It is not necessary to do interface interaction every time for low coupling, which is a waste of performance.

  • When the business volume and team size are small, it is suitable for the sharing mode. In a set of system, it is most reasonable to consider high cohesion and low coupling according to modules; When the business scale is large, it is suitable for self occupied mode and divided into multiple systems. The internal cohesion of each system is high and the low coupling between systems is more reasonable.

4. Bob's Story Case

Finally, we share a Bob's  story to strengthen the understanding of high cohesion and low coupling.

Bob has been a little annoying recently, and this is what happened:
Last month, Bob just joined Z company to be responsible for the products of the inbound system. When he first joined the company, he encountered the resignation of the former product manager. During the handover process, they learned that the WMS system was developed and launched not long ago. However, due to many system problems, the inventory records of the system were seriously inaccurate. In only one month, there was a difference between the book and actual figures of more than 10 million dollars, and the difference was becoming larger and larger, It has seriously affected the company's sales and is forced to solve by the sales department, storage department and financial department every day. The predecessor really couldn't withstand the pressure, so he proposed to leave. Later, the company recruited Bob.

Bob didn't realize the seriousness of the problem until he was directly sent to the CEO by the warehousing business party in an email, and asked the technical department to be responsible for the inventory difference and repair the system problem for one month. In order not to take responsibility, Bob immediately offered to leave, then he was persuaded by the leader to stay, and leader increased the performance bonus for him, because at present, only Bob is the most professional person, so he can only work hard. Under the heavy reward, the two agreed to limit it to one month, and the leader promised Bob enough resources to solve the problem.

Bob called the R & D Manager and the test manager to set up a special team. He started with the business difference data and checked the business with the greatest difference. Soon Bob found the root of the problem according to his own experience: the R & D team of the new WMS system had no experience in inventory processing. When the inventory processing was designed, the business was handled by itself in each business module, and each module was responsible for the inventory addition and subtraction of its own module, and directly operate the inventory table, so it seems that the businesses do not interfere with each other, which seems very decoupled and reasonable.

However, they all ignore the fact that the businesses are parallel, and the businesses such as outbound and inventory counting may also be carried out during inbound. Although each business is carried out separately, once multiple businesses are operated for a SKU at the same time, the inventory processing will restrict each other. Often, the inventory has not been processed in the previous business, and the inventory operation has been changed in the next business, which leads to the disorder of inventory operation, Therefore, there is an inventory difference. It seems that the decoupling design is actually a problem caused by the high coupling of various business and inventory processing.

Current situation of Z company's inventory handling

Such a serious problem, why was it not found during the test? Because there are too few samples during the test, this kind of business concurrency was not detected at all.

After finding the root of the problem, Bob was a little relieved and quickly designed an inventory solution based on experience: take out the inventory processing separately to make it a public service. The whole system can only operate the inventory table based on this service, ensure that the next business operation can be performed after the previous business addition and subtraction is completed, and record the detailed inventory change log.

Externally, it provides public inventory addition and subtraction public services, so that each warehousing business link only needs to process the business logic, and then call the inventory service to complete the inventory processing when the inventory needs to be changed. There is no need to pay attention to the underlying logic of the inventory. In this way, it is the real high cohesion within each business (each business only focuses on processing its own business logic) and low coupling between business and inventory (interacting through a unique interface).

Inventory handling scheme after Bob's design

After the scheme was issued, the technical team completed the reconstruction of the inventory in one week, sorted the businesses one by one according to the size of the difference, and migrated them to the new inventory service. Although the business is still pressing every day, looking at the narrowing of the inventory difference every day, Bob knows that his new scheme works. In this way, the inventory problem can be completely cured in less than one month. 

The above are my personal views on high cohesion and low coupling. Finally, I want to say that the design of high cohesion and low coupling is only the final form of implementation, and their more value is reflected in a structured way of thinking, which is useful in many fields. When doing cohesion, we should learn to summarize and abstract to make the same business and features as compact as possible. When doing coupling, we should learn to split, peel off, reorganize and cohere closely related processes, logic and features, and avoid coupling.

If you like the article, please share it with others with page link, thanks for your supporting! ❤


Leave a comment

Please note, comments must be approved before they are published

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.