Skip to content
Separation of Concerns — Explained with Examples

Separation of Concerns — Explained with Examples

DodaTech Updated Jun 15, 2026 2 min read

Separation of Concerns (SoC) is a design principle that divides a program into distinct sections, each addressing a separate concern or responsibility.

Separation of Concerns (SoC) is a fundamental design principle championed by Edsger Dijkstra. It states that a program should be partitioned into modules that overlap as little as possible. Each module has a single, well-defined responsibility.

Why SoC Matters

When concerns are mixed, changing one aspect of the system risks breaking unrelated features. SoC reduces this risk by isolating concerns into independent modules. It also enables parallel development — different team members can work on different concerns simultaneously.

Real-World Analogy

A restaurant with separate stations: prep, grill, pastry, and expediting. Each station focuses on its own concern. The grill cook doesn’t worry about desserts. If the menu changes, only the affected station adjusts. Mixing all stations into one kitchen would be chaos.

Example: SoC in Web Application

# Mixing concerns — bad
def handle_request(user_id):
    db = connect_to_database()
    user = db.query(f"SELECT * FROM users WHERE id = {user_id}")
    html = f"<html><body><h1>{user['name']}</h1></body></html>"
    print(html)
    db.close()
# Separation of concerns — each layer has one job
class UserRepository:
    """Concern: data access"""
    def find_by_id(self, user_id):
        with connect_to_database() as db:
            return db.query("SELECT * FROM users WHERE id = ?", (user_id,))

class UserTemplate:
    """Concern: presentation"""
    def render_profile(self, user):
        return f"<html><body><h1>{user['name']}</h1></body></html>"

class UserController:
    """Concern: coordination"""
    def __init__(self):
        self.repo = UserRepository()
        self.template = UserTemplate()

    def show_profile(self, user_id):
        user = self.repo.find_by_id(user_id)
        return self.template.render_profile(user)

Related Terms

Single Responsibility Principle, MVC, Encapsulation, Clean Architecture

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro