15/11/2019

Code decoupling

Problems

​Our code is:

 

  1. Hard to refactor. Impossible to refactor a specific module separately.
  2. Any refactor is very likely to break something without us knowing.
  3. Hard to learn, understand and use.
  4. Hard to reuse some of its parts.
  5. Hard to test, tests run slow and coverage is little. Changes inside a module force rewriting tests outside of it.

Solution

Make use of:

 

  1. Modularizing the app further. More small modules. Most important ones are: transactions, payments, timelines, packages.
  2. Creating module APIs and implementing them (using existing code at first)
  3. Events and listeners instead of hardcoding dependencies
  4. Lowering the amount of cross-dependencies

Tight coupling

  • Cohesion (связность) - inside of the modules. Can be low or high.
     
  • Coupling (зацепление) - between modules. Must be low.

Module API

Components:

 

  1. Interfaces for any external APIs (services, repositories etc)
  2. Enums that are used in the API
  3. Events that can be listened externally
  4. Transformers
  5. Models

Discussion

Code decoupling

By TenantCloud

Code decoupling

PHP/Laravel code decoupling

  • 150