This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Abstract Classes initialization parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract Classes initialization parameters" Watch "Abstract Classes initialization parameters" New topic
Author

Abstract Classes initialization parameters

Dennis M Kavanagh
Greenhorn

Joined: Mar 26, 2007
Posts: 6
Hello,

I have three classes.

One is a DataSetRequestor with various fields filled in by the user.

I have an abstract class called DataSet holdoing commonalities, with subclasses for each specific type of DataSet.

I need to get some values from the DataSetRequestor class to the abstract class as initialization parameters.

Any thoughts?

Thank You
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37955
    
  22
You can pass parameters to an abstract class’ constructor.
You can create an anonymous subclass by implementing any abstract methods.

Other people will doubtless think of other ways to do it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Using the constructor is a good way, but you would have to require each of the subclasses to call this constructor. You could also provide a setter method in the abstract class to pass in those parameters.

By the way, the fact that your DataSet class is abstract is completely irrelevant to this question. Remember that despite what you said,
I need to get some values from the DataSetRequestor class to the abstract class as initialization parameters.

you are not passing those values to the class. You are passing them to an object which is an instance of that class. So you would just use any suitable method for passing values into an object.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Abstract Classes initialization parameters
 
Similar Threads
Interfaces.
abstract method
how to use collection for loading multiple classes?
abstract class
Wildcard parameters for abstract methods