Thursday, January 17, 2013

Java (OOP) is sux from the very beginning

I knew for a while that composition must be used instead of inheritance. I just realized that there is no one example (stackoverflow was asked explicitly) when inheritance would be preferred. Never! The very inheritance, the cornerstone of OOP (Java is OOP), is considered a bad practice! Integer extends Number, FilterInputStream extends InputStream, which extends Closable. Java begins with Object whereby every other object inherits a dozen of fields (lock, hash, class) and 11 methods (wait, getHash, getClass) from it.

Notably however, design pattern experts who make us thinking that inheritance is evil and stone age structural composition must always be used instead, promote OOP and the idea that we must replace conditionals with polymorphism! (which is achievable only through inheritance in OOP languages). For no reason [1], [2], [3]!

Update The last bullet is that tight coupling between functions and data is bad.

4 comments:

Anonymous said...

After getting more than 10000 visitors/day to my website I thought your valjok.blogspot.com website also need unstoppable flow of traffic...

Use this BRAND NEW software and get all the traffic for your website you will ever need ...

= = > > http://get-massive-autopilot-traffic.com

In testing phase it generated 867,981 visitors and $540,340.

Then another $86,299.13 in 90 days to be exact. That's $958.88 a
day!!

And all it took was 10 minutes to set up and run.

But how does it work??

You just configure the system, click the mouse button a few
times, activate the software, copy and paste a few links and
you're done!!

Click the link BELOW as you're about to witness a software that
could be a MAJOR turning point to your success.

= = > > http://get-massive-autopilot-traffic.com

Anonymous said...

just dropping by to say hey

Anonymous said...

Just to clarify things, so people don't get it wrong:

> It is wonderful moreover, how design pattern experts
> who make us thinking that inheritance is evil
> and stone age structural composition must
> always be used instead, promote OOP and the
> idea that we must replace conditionals with
> polymorphism (which is achievable only
> through inheritance in OOP languages).

First of all, I've never read that composition should be always used instead of inheritance, the wording is somehow different: Prefer Composition over Inheritance. But there are cases where inheritance is better than composition.

Second, just because you compose your classes, doesn't mean that you cannot use polymorphism. One does not exclude the other. I think you are a little bit stuck in type safety. Let's see a language like Ruby. In Ruby you can use polymorphism without even letting the objects know, that they are used the same way! If objects provide the same method you can treat them likewise. In a static typed language like Java, you can also achieve this, by introducing interfaces. So place an interface with only the methods you like to use and let your classes implement that interface and use composition for code-reuse, you will find yourself in a well-structured system, that favors composition over inheritance and makes intensive use of polymorphism.

So guy, please calm down and little bit and study even a bit more. Thanks.

Anonymous said...

heh