Skip to content

SoC - Separation Of Concerns

  • Single Responsibility Principle and SoC are strongly related
  • Implies separation of different [[concern]]s in different modules
  • Allows to build [[modular system]]s

Concerns we often face with: - [[UI]] - [[Business Logic]] - [[Presentation Logic]] - [[Database]]


Leaking abstractions can ruin the SoC

presentation layer is bothered by [[UI]] concerns

public Color TextColor
{
    get {
        bool result = Validate(text)
        return result ? Colors.Green : Colors.Red;
    }
}

[[Domain]] is bothered by [[Database]]:

void DoWork(Customer customer1, Customer customer2)
{
    if (customer1.Id > 0) {
        // do something
    }

    if (customer1.Id == customer2.Id) {
        // do something
    }
}

  • [[Layer]]s which represent different concerns should be isolated from each other in such a way that none of them should know a bout any intrinsic details of each other.
  • [[SQL procedure]]s implementing [[business logic]] violate SoC but they're way much faster in certain scenarios.