← Foundations path
.NETFoundations 12 / 37

Data vs behaviour

“Which classes should hold data, and which should do the work?”

Some classes are things that remember values, like a loan. Others are jobs that get done, like working out an EMI.

See it

Holds dataremembers valuesDoes workremembers nothingLoanId 0192ab…Amount 5,00,000Rate 9.5Months 60──────────ChangeRate()Emi()QuoteAmount 5,00,000Rate 9.5Months 60no Loan yetMoneyAmount 500.00Emino fields──────────Monthly()5,00,000 · 9.5 · 60EMI 10,500.93
1 / 7 mostly holds data: its values, plus a few methods that guard them, like .

In plain words

Some classes mainly hold data. A Loan remembers its amount, rate and months. Money remembers one amount. Other classes mainly do work. Emi takes numbers in, works out the monthly payment, hands it back, and remembers nothing. For any class, ask: is it a thing that keeps values, or a job that gets done?

Say it in the interview

In the lending API

Three files from the lending API, and their tests. Press Next line to walk through them.

Lending.sln · where these 5 files sit
  • src/Domain/
    • Servicing/
    • Common/
  • tests/Domain.UnitTests/Common/
Diagram · step 1 mostly holds data: its values, plus a few methods that guard them, like .
Holds dataremembers valuesDoes workremembers nothingLoanId 0192ab…Amount 5,00,000Rate 9.5Months 60──────────ChangeRate()Emi()QuoteAmount 5,00,000Rate 9.5Months 60no Loan yetMoneyAmount 500.00Emino fields──────────Monthly()5,00,000 · 9.5 · 60EMI 10,500.93
Loan.cs · line 4 · 1 of 6The Loan from the . It is mostly data: four values, each kept per object.

What they ask next

Interviewers check that you can explain every line. Tap a question to open it.

Traps

With AI tools

GitHub's Copilot best-practices guide lists deep business logic among the tasks to keep for humans. When you ask an AI tool for an on a new screen, point it at Emi.cs, so it reuses the one formula instead of writing a second.

Read more: Microsoft Learn: records · Microsoft Learn: static classes · Microsoft: value objects in a domain model · Martin Fowler: anemic domain model · GitHub Docs: Copilot coding agent best practices