Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Refactoring Catalog 5: Simplifying Conditional Logic — Decompose/Consolidate Conditional, Guard Clauses, Replace Conditional with Polymorphism and Introduce Special Case
Conditional refactorings turn complex ifs into named functions, guard clauses, switch expressions or polymorphism; but a special case that removes null checks can also remove a side effect the check was quietly preventing. The post transforms Bookstore's CheckoutPolicy with seven refactorings, showing with real output dotnet format's IDE0066 fix, a special case that shows a guest 12 points while the tests stay green, and a Debug.Assert that disappears in a Release build.
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.