C# Polymorphism with Template, Strategy, Visitor

Learn how polymorphism in C# using Template Method, Strategy, and Visitor patterns makes your code flexible, maintainable, and reusable.

July 16, 2025 · Last modified: September 19, 2025 · 5 min

C# Interfaces: Default Methods for Compatibility

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: September 19, 2025 · 11 min

Square-Rectangle Problem: Lessons on Liskov Substitution

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: September 20, 2025 · 12 min

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

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 · Last modified: September 19, 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

Open-Closed Principle: Smart Use, No 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: September 20, 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

Single Responsibility Principle: One Reason to Change

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: September 20, 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
×