Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Classes initialization parameters

 
Dennis M Kavanagh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48645
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic