C# Default Interface Methods: Future-Proof and Backward-Compatible APIs

A practical guide to C# Default Interface Methods: how to use them, when to avoid them, and how they help you build future-proof APIs.

July 15, 2025 · Last modified: July 30, 2025 · 11 min

What the Square-Rectangle Problem Reveals About LSP

TL;DR LSP means you can use subtype objects anywhere you use base type objects without breaking code. Square/Rectangle inheritance that breaks existing code? That’s a classic LSP problem. Watch for subclasses that throw unexpected exceptions or silently change behavior. When behaviors are too different, reach for composition instead of inheritance. Make interfaces that clearly show what objects can and can’t do to avoid surprises. LSP violations often sneak past unit tests and show up as runtime bugs. The Liskov Substitution Principle isn’t just academic theory - it helps you avoid those “it worked yesterday” bugs that show up in production. When a subclass doesn’t behave like its parent promises, your code breaks in ways that unit tests often miss. ...

July 14, 2025 · Last modified: August 7, 2025 · 12 min

Dependency Inversion Principle in C#: Flexible Code with ASP.NET Core DI

Discover how the Dependency Inversion Principle makes your C# code flexible and testable. Learn to use ASP.NET Core DI to depend on abstractions, swap implementations, and build maintainable, scalable applications with real-world examples.

July 13, 2025 · 3 min

Encapsulation Best Practices in C#: Controlled Setters vs Backing Fields

Discover the best practices for encapsulation in C#. Learn when to use auto-properties, when to switch to backing fields, and how to keep your property setters clean, focused, and maintainable with practical examples and actionable guidelines.

July 12, 2025 · 5 min

Use OCP Smartly - No Need for Plugin Overkill

TL;DR: The Open/Closed Principle (OCP) states: classes should be open for extension, but closed for modification. You don’t need to create a plugin for every new feature, favor simpler patterns like strategy, inheritance, or composition. Start with well-named abstractions; introduce extensibility points only when real change is expected. Keep code maintainable by balancing extension points with simplicity. Overengineering is a bigger risk than occasional refactoring. The Open/Closed Principle isn’t about making everything extensible. It simply means that your core business logic should be closed to modification but open to extension. The real skill is knowing when to apply it and when you’re just over-engineering your code. ...

July 11, 2025 · Last modified: August 7, 2025 · 10 min

Violating SOLID for Performance: When It’s Okay and How to Isolate It

Discover when it’s justified to break SOLID principles for performance in C#. Learn how to measure, isolate, and document exceptions, see real-world trade-offs, and keep your codebase maintainable, even in the engine bay of high-throughput systems.

July 10, 2025 · 10 min

Avoiding N+1 Queries in EF Core: Include() vs SplitQuery()

A practical guide to fixing N+1 queries in EF Core using Include and AsSplitQuery, with code samples and performance tips.

July 8, 2025 · Last modified: July 10, 2025 · 11 min

What “One Reason to Change” Really Means in SRP

TL;DR: SRP means each class or module should have only one reason to change. Split validation, data access, and business logic into separate classes. SRP improves maintainability, testability, and scalability. Use C# 12 features like primary constructors and records for clean separation. Avoid “God” classes and mixing unrelated responsibilities. SRP is the foundation for applying other SOLID principles. Refactor large classes by extracting focused components and using dependency injection. The Single Responsibility Principle gets misunderstood more than any other SOLID principle. It’s not about doing one thing, it’s about having one reason to change. When your class changes for multiple business reasons, you’ve violated SRP and created a maintenance nightmare. ...

July 7, 2025 · Last modified: August 7, 2025 · 8 min

Avoiding Boxing with Struct Dictionary Keys in C#: Performance and Best Practices

Discover why structs as dictionary keys can cause hidden allocations in C#. Learn how to implement IEquatable, use readonly and record structs, and write allocation-free, high-performance code for hot paths.

July 6, 2025 · 4 min

Guard Clauses in C#: Cleaner Validation and Fail-Fast Code

Discover how guard clauses in C# simplify validation and error handling. Learn to write fail-fast code, avoid nested conditionals, and keep business logic clean with modern language features and reusable helpers.

July 6, 2025 · 4 min
×