Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Template Method Pattern: Algorithm Skeletons, Hooks and the Delegate-Based Alternative
Template Method fixes an algorithm's skeleton in a non-overridable base class method and leaves the varying steps to abstract methods or empty hooks. The hook silently skipped by a forgotten override (CS0114), Stream.CopyTo and BackgroundService.ExecuteAsync whose behavior changed in .NET 10, the virtual-call-in-constructor trap (CA2214), and building the same flow with delegates through composition.
Composition over Inheritance: Fragile Base Class, Delegation and Pluggable Behavior
Inheritance ties a subclass to its base class's implementation details, so a harmless change in the base class can silently break a subclass, while composition and delegation depend only on the contract. The fragile base class problem shown with real output, the class explosion when behavior grows along two axes, and where inheritance is right: Collection<T> hooks and sealed.
Polymorphism in C#: virtual, override, new and Abstract Classes
Letting the runtime decide with virtual and override, an if-free cart loop for shipping costs, base calls and overriding ToString, hiding with new and the CS0114 trap, abstract classes and the template method, sealed override and the NullReferenceException of calling a virtual method from a constructor.
Inheritance in C#: base, sealed and the Constructor Chain
Inheritance with Product, Book and EBook: what a derived class sees and protected, the constructor chain with base and the reverse order of field initializers, upcasting, downcasting, is and as, stopping derivation with sealed, and how an Order derived from List breaks encapsulation.
What's New in EF Core 7: ExecuteUpdate, ExecuteDelete, JSON Columns and TPC
ExecuteUpdate/ExecuteDelete, ToJson for owned types in JSON columns, TPC inheritance, IMaterializationInterceptor, FromSql and SqlQuery<int> in EF Core 7, plus moving from EF Core 6 with breaking changes like Encrypt=True and HasTrigger.
Inheritance Mapping in EF Core: TPH, TPT and When to Choose Which
How does EF Core turn a class hierarchy into tables? We compare TPH with its discriminator column and TPT with a table per type using real SQL output, and look at silent pitfalls like a subclass missing from the model.