Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The business codebase I'm working on now was written by OOP crazy people who thought inheritance was the solution to every line of duplicated code. When they hit roadblocks, they filled the base class with things like if(this.GetType() == typeof(DerivedClass1)){...

I would do anything to have the duplication instead.



If you're truly OOP crazy you will always find ways to avoid resorting to branching on types or even avoid branching altogether (just on the language level of course). "There's a design pattern for that" :-)


Once you ask what the class is you're no longer even "OOP crazy".

You've just capitulated to the complexity and do whatever it takes.

I don't want to sound (too) condescending. I know how easy the best intentions can lead a project there. This job is hard.


Checking for the type is the exact opposite of OO.

The correct OO would be to think about what the check represent, maybe abstract it in a base interface with pure abstract methods and derive from that interface.

What you describe is what people without understanding of OO do when they come from a language without OO.


Very relatable. And they even have the guts to call this code "SOLID"


Then the very same people learn that inheritance bad, composition good, and they'll create abstractions with no meaning on their own, which call 10 vague other abstractions (but hey, no inheritance!). Figuring out what happens there is even worse than with inheritance. Some people grow out of it, fortunately (mostly after having to deal with shit like that once or twice).


> ...they'll create abstractions with no meaning on their own...

As if that doesn't happen with inheritance!

The dark pattern is using inheritance as an alternatve way of implementing composition. Anyone who thinks that "inheritance bad, composition good" is the proper response to this is probably as confused about the issue as those making the mistake in the first place.

To be clear, you are clearly not making that claim yourself, but you are invoking it to make a straw man argument.


> they filled the base class with things like if(this.GetType() == typeof(DerivedClass1)){

That defeats the purpose of polymorphism.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: