This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""Driver" class?" Watch ""Driver" class?" New topic
Author

"Driver" class?

David Eason
Greenhorn

Joined: Oct 31, 2001
Posts: 14
I have a book Pure Java 2 by Kenneth Litwak. The author is fond of creating an extra class, which he calls a driver class, to house the main() method. He says this is purer object oriented design. For example:

Is there any value to this approach? This is my first post by the way, and I am happy to have found this site.

[This message has been edited by David Eason (edited November 06, 2001).]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
From an OO point of view - a Cat is a Cat, not an application. Applications have main methods and should therefore be in a class that represents an application. All of our production code has the main method in a class that has the same name as the application itself.
However from a practical point of view, sometimes (especially when just playing with code) it is just plain EASIER to stick the main in one of the classes and get on with it.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Deitel and Deitel use a similar approach. For (almost) every class Xxx they write a TestXxx class containing a main() to make sure the methods in the class work properly.

This is one approach to unit testing.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
David Eason
Greenhorn

Joined: Oct 31, 2001
Posts: 14
It seems to have the side effect of keeping you from making your Cat class public. Although in real life, I guess it would have package scope instead of public scope so it wouldn't matter.
I am in the "playing with code" phase right now anyway.
Thanks for the replies!

[This message has been edited by David Eason (edited November 06, 2001).]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Well you can always put your Cat class in its own file, then it can be public.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "Driver" class?
 
Similar Threads
could anybody help me to find out the answers for these questions
begin execution of a thread -- start or run?
ibm test question
Another passing by reference question
ClassCastException