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
I hope this young programmer will not put all them code in one file after this advice :)
ReplyDeleteIf he put them in his code... I would laugh... and then kill him for doing it.
ReplyDeleteHere 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. ;-)
Interesting.............
ReplyDelete