# Wednesday, October 22, 2003
« Ghosts | Main | PDC »
Private Super Classes

While trying to get Stuart Ballard's Japitools to work on a netexp generated export of IKVM's classpath.dll, I encountered java.awt.BufferCapabilities.FlipContents. This public (inner) class has non-public base class (java.awt.AttributeValue). What kind of a bizarre design is that?

I had never realised that the Java language allowed this. Fortunately, the C# designers didn't make the same mistake.

Note that a similar issue exists for fields (and method arguments). In Java it is legal to have a public field of a non-public type, or a public method that takes an argument of a non-public type. C# prohibits both of these.

I fixed netexp to export non-public base classes (and I should do the same for interfaces, fields and method arguments/return type).

Wednesday, October 22, 2003 6:36:30 PM (W. Europe Daylight Time, UTC+02:00)  #    Comments [4]
Wednesday, October 22, 2003 7:53:10 PM (W. Europe Daylight Time, UTC+02:00)
It's interesting the things that C# prohibits but the CLR allows. If I read your comment right, you're saying that C# prohibits this situation, but the CLR allows it, so you can actually compile Java code that has this design without having to correct for it, and it will run ok, so the only problem is making sure netexp exports a coherent hierarchy back to Java.

I'd have expected the CLR to prohibit it, in which case you'd have more complex issues - you'd have to make the base class public but somehow indicate by attributes that it's supposed not to be, so that Java code couldn't use it.

Either that, or I'm confused :)
Wednesday, October 22, 2003 11:16:04 PM (W. Europe Daylight Time, UTC+02:00)
You're absolutely right. I'm lucky that the CLR allows it, if it didn't I'd have to jump through (even) more hoops to compile the Java classes.
It is not surprising that the CLR allows things that are bad from an OO design perspective. Its job is not to promote writing "good" code.
As an aside, it can actually be surprisingly difficult to figure out what is reasonable for the CLR to accept or not. Microsoft did a good job, but I certainly don't agree with all their decisions.
Thursday, October 23, 2003 6:31:39 PM (W. Europe Daylight Time, UTC+02:00)
Would you agree that a public class implementing a non-public interface is actually legit? It may be that internal code needs it to implement the interface even though external code doesn't care.

Does C# allow this?
Sunday, October 26, 2003 5:59:07 PM (W. Europe Standard Time, UTC+01:00)
Implementing private interface is definitely legit. C# allows it and it is even more powerful than in Java, because the interface implementation methods don't have to be public.
Comments are closed.