Enterprise Software Engineering with C# and .NET: Architecture, Design Patterns, and AI-Enabled Systems · HIT

Week 3   Part II · API and Persistence

SOLID Principles and Clean Code

Instructor lesson plan: lecture (2 h) and practice (2 h).

Learning objectives

Tools this week

.NET test runnercode analyzersrefactoring toolsarchitecture sketches

🎓Lecture · 2 hours

0:00-0:1010 minRetrievalStudents show one entity and one invariant from week 2.
0:10-0:3525 minSingle responsibility and cohesion
  • Reasons to change as the practical test.
  • Spotting classes that mix persistence, validation, and business rules.
0:35-0:5520 minOpen-closed and strategyReplace conditional policy blocks with named policies only when variation is real.
0:55-1:1015 minLiskov and interface segregationContracts, substitutability, and focused interfaces.
1:10-1:2010 minBreak
1:20-1:4525 minDependency inversion
  • High-level policy should not depend on low-level details.
  • Interfaces owned by the application need, not by infrastructure convenience.
1:45-2:0015 minClean code in teamsNames, small functions, reviewability, and refactoring as a normal activity.
Common misconception to confront.

Students often think: every class needs an interface.
Set it straight: introduce an interface when it protects a boundary, supports variation, or protects a boundary.

Check for understanding
What is a reason to change?
A business, policy, persistence, integration, or presentation concern that would force editing the class.
Who should own an abstraction?
Usually the higher-level policy that needs the behavior, not the low-level implementation that happens to provide it.
Key takeaways.

📚Reading & resources

💻Practice · 2 hours

0:00-0:2020 minSmell huntReview a deliberately messy service and identify responsibilities.
0:20-0:5535 minGuided refactor
  • Extract policies and dependencies.
  • Keep behavior stable after every small step.
0:55-1:1015 minTeam reviewEach team names one class in its project with too many reasons to change.
1:10-1:2010 minBreak
1:20-1:5030 minProject refactorTeams refactor one domain or service area and document the preserved behavior.
1:50-2:0010 minProject-integration briefSubmit a short note explaining the refactor and why it improves maintainability.

Project integration (this week)

PreviousWeek 2: Modern C#NextWeek 4: ASP.NET Core Web API