Sunday, September 21, 2008

Inheritance, Interfaces and Packages

As I ploughed on through the trail, I began to feel there might be merit in a Java Tutorial for ninnies, such as myself. Such a tutorial would include the sections Objects and Classes, and then it would stop for a breather, and perhaps provide simple (but not too simple) practical examples on how it all works. Perhaps later in this blog I might record how I applied the previous two lessons, but for now I'll plough on, because that's what I did when I first followed the trail.

I thought the bicycle analogy worked really well to explain the concept of inheritance, but I couldn't help racking my brains and wondering when I would ever apply the knowledge myself.

And after struggling to absorb the rulLinkes on Objects and Classes, when I read the page on interfaces, I asked the questions: Why? What is this for? How does this help me to write good code? When would I or when should I use an interface?

I'd wager that 90% of grass roots programmers, by which I people working for themselves as opposed to software giants, would use an object once and only once, in which case the class is already a redundant layer of classification. Under such circumstances, adding an interface would just add another redundant layer.

So I reached the page on packages after struggling with two pages which didn't really apply to me, and I was tired, and didn't properly absorb it. Now I know it is in the essence of hypertext that the reader can jump from one page to another. But it is also human nature, when one is following a trail, to follow the trail. I perhaps another way of improving these tutorials for real beginners would be to offer forks in the trail, with one path for professionals or career students, and a shorter path for real beginners or amateur and part time programmers.

And even when I read the page again, I am not sure how it helps me to produce and distribute my own Java application. I guess it is nice to know that people have written hundreds of classes and interfaces, and nicer still to know that they have organised them neatly into packages and libraries. But how does that help me, the Java learner, to write my application?

For example, if my application uses a class written by someone else, when I distribute my application, do I need to distribute the whole package, or the whole library? Do I even need to distribute the class file? Or do I assume the whole package/library structure remains stable over time and will already reside on any computer with the current JRE installed. The answers to these questions may be obvious to the experts, but they are not obvious to me, and I'd wager they are not obvious to many aspiring java programmers using the Java Tutorial.

No comments: