Home > Article > Backend Development > The data between Yii2 two modules need to call each other. How to design to minimize the coupling?
There are two modules A and B. Modification of the content in the database of module A must cause the data of module B to be modified together. Module A can also read some data of module B.
How to design to minimize the coupling between modules?
There are two modules A and B. Modification of the content in the database of module A must cause the data of module B to be modified together. Module A can also read some data of module B.
How to design to minimize the coupling between modules?
Regard Customer as A and Order as B. In this example, the value in B is modified.
$customer = Customer::findOne(123);
$order = new Order();
$order->subtotal = 100;
// ...
// setting the attribute that defines the "customer" relation in Order
$order->customer_id = $customer->id;
$order->save();
Add a services layer to handle business logic.
The problem of cross-module calling will not occur. Because the services layer has nothing to do with modules.