Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Driver" class?

 
David Eason
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marilyn de Queiroz
Sheriff
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Eason
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you can always put your Cat class in its own file, then it can be public.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic