Misuse of Inheritance in Web Controllers

Inheritance is a common feature in OOP languages to specialise classes/types and allows polymorphism. It is easy to reuse the common functionality between classes by moving it to the parent class and use by the child classes. Without being mindful of software design principles, it can lead to increased coupling and responsibilities, making existing code hard to change. We’ll take you through a situation in C# MVC’s controllers and show how it improves the design by refactoring. The class diagram shown illustrates a fictitious online photo stock website.

misuse-inheritance-1 class diagram before refactor

This is a violation of interface segregation principle (ISP) which states that no client should be forced to depend on methods it does not use. In this case, BaseController has multiple methods and through inheritance, all of the child controllers have access to them but only use some of them and does not need some of them. When there’s a change in BaseController’s GetCredit, the child controllers which use it might be affected and should be checked and tested.

Continue reading

My adopted dog – Girl Girl the cocker spaniel ft. www.adoptadog.sg

adopt-a-dog-wei-ket-cocker-spaniel

I adopted Girl Girl the cocker spaniel when she was 6 from a factory at Tuas. I’m her 3rd (and final) owner, the 2nd owner, an uncle in his 50s didn’t know much English and thus named her Girl Girl, which I didn’t feel a need to change since she responds to it. Uncle could not bring Girl Girl home cos his existing dog could not get along with her, he could only keep her at the factory, where he returned on Sat and Sun to bathe her, feed her and play with her. Uncle was retrenched and had no choice but to ask around for new adopters. Continue reading

Moving on to new frameworks: ASP.NET MVC 5 and React.js

Moving on to new frameworks: ASP.NET MVC 5 and React.js

There are many software developers that have used ASP.NET Web Forms development framework for building solutions. In late 2014, we conducted a feasibility study for ASP.NET MVC5 framework by applying it in multiple small projects.

What is React.js? Many programmers have been pretty curious about this thing that we have been talking about. I’ll try to explain that exactly here. Continue reading