Applying OOP in ASP.NET Core

This post explores the four pillars of OOP in ASP.NET Core: encapsulation, abstraction, inheritance, and polymorphism. It provides practical examples and explains how these principles improve code maintainability, testability, and architecture in modern C# web APIs.

August 10, 2025 · Last modified: September 3, 2025 · 8 min

Interface Segregation Principle: No Unused Methods

TL;DR ISP means interfaces should be small and focused on client needs. Avoid “God” interfaces that force clients to implement unused methods. Split large interfaces into cohesive, role-based interfaces. Use C# 12 features like default interface methods for flexibility. ISP improves maintainability, testability, and reduces coupling. Refactor fat interfaces by extracting related methods into separate interfaces. Interface Segregation Principle stops you from creating huge interfaces that force clients to implement methods they’ll never use. When interfaces get too big, your implementations end up filled with empty methods and unnecessary dependencies. ...

July 18, 2025 · Last modified: September 20, 2025 · 12 min

Prefer Interfaces Over Abstract Classes in C#

Learn why preferring interfaces over abstract classes in C# improves code flexibility, testability, and maintainability for robust .NET applications.

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

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

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

C#: Abstract Class or Interface? 10 Questions to Ask

Quick Reference Table Feature Abstract Class Interface When to Use Inheritance Single only Multiple allowed Abstract: shared logic; Interface: contracts Implementation Can provide Contract only Abstract: code reuse; Interface: flexibility Constructors Supported Not allowed Abstract: initialization; Interface: pure contracts State/Fields Yes No Abstract: data sharing; Interface: behavior only Performance Slightly faster Virtual dispatch Abstract: hot paths; Interface: most scenarios Testing Can be difficult Easy with mocks Abstract: integration tests; Interface: unit tests Common Pitfalls: ...

July 1, 2025 · Last modified: August 15, 2025 · 11 min

How Does Composition Support the SOLID Principles? (C# Examples & Best Practices)

Discover how composition helps you follow the SOLID principles in C#. See practical examples for each principle, learn why composition is more flexible than inheritance, and get actionable tips for writing robust, testable, and maintainable code.

June 30, 2025 · 4 min

Composition Over Inheritance in C#

Discover why composition is often a better choice than inheritance in C#. This article explains the drawbacks of deep inheritance, demonstrates how to use composition for flexible and maintainable code, and provides practical tips for applying these principles in real-world projects. Includes code examples and guidance for testable, scalable software design.

June 29, 2025 · Last modified: September 20, 2025 · 12 min

5 Essential Benefits of Immutability in C# Programming

TL;DR: Immutable objects can’t be changed after creation. In C#, this can make your code safer, easier to test, and bug-resistant, especially in multithreaded or async scenarios. Have you ever had a bug where some object mysteriously changed its value? Or spent hours debugging a weird race condition? Immutability might be the solution you need. In simple terms, immutable objects can’t be changed after they’re created. Instead of modifying an existing object, you create a new one with the updated values. It’s like the difference between editing a document and making a new copy with your changes. ...

June 20, 2025 · Last modified: July 24, 2025 · 8 min

C# Constructor Chaining - Why It Matters for Clean Code

Constructor chaining in C# reduces code duplication by allowing one constructor to call another. Learn how to use this technique effectively with examples, best practices, and when to avoid it.

June 20, 2025 · Last modified: July 24, 2025 · 6 min
×