BolEnglishLearn · Play · Win
Login

🗂️ Software Design Principles · Core Principles

🗂️

Separation of Concerns

Design PrincipleCoreModule 2

Different kinds of work should be separated.

Keep presentation, business rules, data access, and integrations distinct.

💡 In practice

The web page collects input; a service validates it; a repository saves it.

🖼️ CONCEPT PICTURE
A picture to help remember Separation of Concerns
The web page collects input; a service validates it; a repository saves it.

💡 Like a restaurant: the waiter takes your order, the chef cooks, the cashier handles money — one person doing all three means chaos.

💡 Learn🛠️ Apply🎯 Check

💡 Why it matters

When screen code, business rules and database code are tangled together, you cannot change one without risking the others. Keeping layers separate lets you swap the database, redesign the page, or test the rules on their own. It makes a large system understandable one layer at a time.

🛠️ How to achieve it

1
Name your layers
Decide clear layers such as presentation, business logic, and data access, and give each its own folder.
2
Let layers talk through contracts
Have one layer call the next through a small, clear interface instead of reaching inside it.
3
Keep rules out of the screen
Put decisions like pricing or eligibility in a service, not inside a button click handler.
4
Isolate the outside world
Wrap databases and third-party services behind their own layer so the rest of the code does not depend on their details.

⚠️ Signs of trouble

  • •Business rules are written inside page or button-click code.
  • •A database query sits in the middle of the screen layout.
  • •Changing the database forces changes across the whole app.
  • •You cannot test the rules without starting the user interface.
⚠️ Common mistake: Writing validation, pricing and SQL all inside one page event handler. Move each kind of work into its own layer so they can change independently.

🎯 Quick check

Score: 0/3

Three questions to test the idea.

  1. 1. Where should business rules like pricing live?

    Answer: In a service layer, not in the screen code

    Rules belong in their own layer so they can be tested and changed without touching the screen.

  2. 2. Why wrap the database behind its own layer?

    Answer: So the rest of the app does not depend on its details

    Isolating data access lets you change or swap the database without rewriting the whole app.

  3. 3. What is a symptom of poor separation of concerns?

    Answer: SQL queries mixed into screen layout code

    Database code sitting inside the presentation is a classic sign the concerns are tangled.

🔑 Key terms

Layer
A group of code that does one kind of work, like presentation or data access.
Presentation
The part that shows screens and collects user input.
Business logic
The rules and decisions that make your app useful.
Data access
The code that reads and writes to the database.

✅ Review checklist

📊 Your progress

0%
Mark this topic learned to track it.
Saved in this browser.
🚀 Got it?
Mark it learned and move to the next topic.
Next topic →