R
Rhino
I have a question about abstract classes but I'm going to need to give you
some of the background before the question makes much sense. Please bear
with me.
I've decided that my project, which writes my resume in a variety of
different formats - HTML, ASCII, PDF for starters - would benefit from an
abstract class. I'm calling this abstract class ResumeWriter. There will be
one class for each each of the resume formats and each of these will extend
ResumeWriter so I'm calling them ResumeWriterHtml, ResumeWriterAscii and
ResumeWriterPdf. In other words, ResumeWriterHtml extends the abstract
ResumeWriter and writes the HTML version of the resume and so on.
The ResumeWriter abstract class includes:
- a number of concrete getters, one for each of the things that the
ResumeWriterHtml, ResumeWriterAscii, and ResumeWriterPdf classes will get
from the ResourceBundle that supplies the data to all of the classes whose
names start with 'ResumeWriter'
- several abstract write methods, one for each portion of the resume, e.g.
writeCandidateInformation(), writeEmploymentHistory(),
writeSoftwareSkills(). In the subclasses, ResumeWriterHtml et. al., each of
the abstract methods will be implemented to write that portion of the resume
in the appropriate format, e.g. the writeSoftwareSkills() method will write
software skills information in HTML format in ResumeWriterHtml and in PDF
format in ResumeWriterPdf and so on.
I'm reasonably confident that this is a sensible way to do this from a
design point of view and the code already works so I know that this is a
workable approach.
Now, here's where I run into problems. In some of the ResumeWriter
subclasses, the write() methods display slightly different data than in
others. For instance, the ResumeWriterAscii class displays only the heading
"EmploymentHistory" and then an array called "EmploymentHistoryData" but the
ResumeWriterHtml displays additional information, specifically some text
that serve as column titles for the different aspects of each job, namely
"From/To", "Employer", "Role", and "Main Tools Used" for those columns of
the HTML table that displays the employment history.
This suggests to me that I need _two_ abstract methods called
writeEmploymentHistory(); one has only two arguments, EmploymentHistoryText
and EmploymentHistoryData, while the other version also has the same two
arguments plus four additional arguments, FromToText, EmployerText,
RoleText, and MainToolsText. Now, I know that this is simply overloading the
writeEmploymentHistory() method and that this is perfectly fine in an OO
program.
The problem for me is that I apparently have to implement _both_ versions of
writeEmploymentHistory() in each class that subclasses ResumeWriter, even
though only one of the two methods will be used in any given subclass of
ResumeWriter. And that makes me uneasy: I find myself wondering if I am
doing the right thing when I implement multiple versions of the same method
in a given subclass even though I will only use one of them. Implementing
methods that I'm not going to use doesn't seem right somehow.
Can someone who is stronger in OO Analysis and Design help me figure out if
I am doing the right thing here? If not, what should I be doing differently?
One other small issue related to the main problem. In the version of the
overloaded method that I am NOT using, it seems to me that the easiest thing
to do is just leave the method body empty with a comment that it is not
being implemented because it is not appropriate for this subclass. However,
if I do that, I get compiler warnings that the parameters for that method
are never used. I know I could disable those warnings in the compiler but
I'd rather avoid that and just put some sort of do-nothing code in the
method body to satisfy the compiler that the parameters are used, even if
the use is trivial. What is the most trivial thing I can do with each
parameter to satisfy the compiler that the parameter is being used? I'm
looking for something that would be harmless if it were executed and that
would be more-or-less harmless looking to anyone who sees the code, i.e.
something that seems to be obvious do-nothing code.
Rhino
some of the background before the question makes much sense. Please bear
with me.
I've decided that my project, which writes my resume in a variety of
different formats - HTML, ASCII, PDF for starters - would benefit from an
abstract class. I'm calling this abstract class ResumeWriter. There will be
one class for each each of the resume formats and each of these will extend
ResumeWriter so I'm calling them ResumeWriterHtml, ResumeWriterAscii and
ResumeWriterPdf. In other words, ResumeWriterHtml extends the abstract
ResumeWriter and writes the HTML version of the resume and so on.
The ResumeWriter abstract class includes:
- a number of concrete getters, one for each of the things that the
ResumeWriterHtml, ResumeWriterAscii, and ResumeWriterPdf classes will get
from the ResourceBundle that supplies the data to all of the classes whose
names start with 'ResumeWriter'
- several abstract write methods, one for each portion of the resume, e.g.
writeCandidateInformation(), writeEmploymentHistory(),
writeSoftwareSkills(). In the subclasses, ResumeWriterHtml et. al., each of
the abstract methods will be implemented to write that portion of the resume
in the appropriate format, e.g. the writeSoftwareSkills() method will write
software skills information in HTML format in ResumeWriterHtml and in PDF
format in ResumeWriterPdf and so on.
I'm reasonably confident that this is a sensible way to do this from a
design point of view and the code already works so I know that this is a
workable approach.
Now, here's where I run into problems. In some of the ResumeWriter
subclasses, the write() methods display slightly different data than in
others. For instance, the ResumeWriterAscii class displays only the heading
"EmploymentHistory" and then an array called "EmploymentHistoryData" but the
ResumeWriterHtml displays additional information, specifically some text
that serve as column titles for the different aspects of each job, namely
"From/To", "Employer", "Role", and "Main Tools Used" for those columns of
the HTML table that displays the employment history.
This suggests to me that I need _two_ abstract methods called
writeEmploymentHistory(); one has only two arguments, EmploymentHistoryText
and EmploymentHistoryData, while the other version also has the same two
arguments plus four additional arguments, FromToText, EmployerText,
RoleText, and MainToolsText. Now, I know that this is simply overloading the
writeEmploymentHistory() method and that this is perfectly fine in an OO
program.
The problem for me is that I apparently have to implement _both_ versions of
writeEmploymentHistory() in each class that subclasses ResumeWriter, even
though only one of the two methods will be used in any given subclass of
ResumeWriter. And that makes me uneasy: I find myself wondering if I am
doing the right thing when I implement multiple versions of the same method
in a given subclass even though I will only use one of them. Implementing
methods that I'm not going to use doesn't seem right somehow.
Can someone who is stronger in OO Analysis and Design help me figure out if
I am doing the right thing here? If not, what should I be doing differently?
One other small issue related to the main problem. In the version of the
overloaded method that I am NOT using, it seems to me that the easiest thing
to do is just leave the method body empty with a comment that it is not
being implemented because it is not appropriate for this subclass. However,
if I do that, I get compiler warnings that the parameters for that method
are never used. I know I could disable those warnings in the compiler but
I'd rather avoid that and just put some sort of do-nothing code in the
method body to satisfy the compiler that the parameters are used, even if
the use is trivial. What is the most trivial thing I can do with each
parameter to satisfy the compiler that the parameter is being used? I'm
looking for something that would be harmless if it were executed and that
would be more-or-less harmless looking to anyone who sees the code, i.e.
something that seems to be obvious do-nothing code.
Rhino