This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJA Question About Ancestor and Sub Classes

 
Oscar Hansen
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading SCJA book by Cameron McKenzie and on page 166, I did not understand the answer to a question. Can someone explain me:

Sub classes:
- Should not be used as a method parameters when an ancestor class will suffice.

Thanks in advance!
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic idea is that you always want to use the most general component whenever possible.

So, if I have a method, and all it does is print out the toString() method, I shouldn't force the argument to be a String, when I could just make the argument an Object. After all, every instance of an Object has a toString() method.

The more general, or abstract an argument is, the more flexible the method becomes. It makes your code more flexible and pluggable. That's the general idea.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic