This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract Classes initialization parameters" Watch "Abstract Classes initialization parameters" New topic

Abstract Classes initialization parameters

Dennis M Kavanagh

Joined: Mar 26, 2007
Posts: 6

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

Joined: Oct 13, 2005
Posts: 38087
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

Joined: Oct 14, 2005
Posts: 18541

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
abstract method
how to use collection for loading multiple classes?
abstract class
Wildcard parameters for abstract methods