Monday, April 16, 2012

Public, Protected, and Private Interfaces... Yes Interfaces.

One of the junior developers came to me on Friday and asked if an interface could be private, or protected. I said sure, but it must be an inner interface. The interface must be contained within a containing class. So I decided to create a couple of examples of interface fun for you to appreciate.

The NetBeans project is located here: interfaces.zip

code

3 comments :

Unknown said...

I hope this young programmer will not put all them code in one file after this advice :)

John Yeary said...

If he put them in his code... I would laugh... and then kill him for doing it.

Here are my thoughts on it. Just because you can create this strange assortment of interfaces, and inner classes does not mean you should.

There are cases where you might use an interface that is private, and the inner classes which are in the example are often seen as listeners.

However, if I came across this code in production I would fix it, or make the person who did it fix it.

I do a Java Certification Boot Camp where I have code like this though. It is instructional. ;-)

Unknown said...

Interesting.............

Popular Posts