tags:

views:

263

answers:

5

If we have:

public interface Foo{}

public class Bar implements Foo{...}

Is there a difference between:

public class BarBar extends Bar implements Foo{..}

and

public class BarBar extends Bar{..}

I see a lot of code like this and it always confuses me. Does BarBar need to implement Foo? I mean since it extends Bar to begin with isn't that already there? I guess my question is, what purpose does implementing Foo in BarBar serve here?

+7  A: 

The main difference is 15 completely unnecessary characters :-)

When your parent class implements some interface, all interface methods are either implemented by it or are defined (explicitly or implicitly) as abstract. Either way, your class extending the parent class inherits all those methods and implicitly implements the original interface.

ChssPly76
+1  A: 

There is no difference. The extra implements there is harmless, but useless.

Pavel Minaev
A: 

There is no reason to implement foo. Because bar is a foo barbar will be as well.

Jataro
A: 

Well I agree with all the comments that has been said about this issue that its really unnecessary implementation although I might do that in case I want to override the behavior of barbar concerning foo implementation so I might do that to enforce overriding those methods and make the IDE auto implement it for me!!

But its the same thing as overriding those functionality in barbar

agawish
+1  A: 

It could be argued that the second "extends X implements Y" is verbose but the extra few chars are a good reminder. Take a look at ArrayList etc I'm pretty sure they use the long form - extends AbstrsvtList implements List.

In the end most developers are fast typers so the extra few chars cost practically no time to type. Why are a so many goals about typing less when it should be about clarity and eliminating ambiguity and not stating all the facts...

mP