noob question on abstract classes
Ok. I have an assignment for class. It should be simple. Except... I don't understand what the teacher is asking for.
Here's the assignment, my question is posted below:
/*Hallmark has asked you to implement a system for them so that
* a user can choose from a list of available cards. There are
* 9 cards to choose from: Christmas, Valentine's, Birthday, Get
* well soon, Anniversary, New baby, Thank you, Congratulations,
* and blank. Your program asks the user who the card is for and
* who it is from. If it is a birthday card, it also asks how old
* the recipient is. If it is a blank card it asks what personal
* message the sender would like to include. If it is a Valentine's
* day card it personalizes the card by adding XOs to the end of
* the card (hugs and kisses) based on the length of the recipient's
* name. Create the cards by extending an abstract class Card and
* using an abstract method called makeCard that is defined for
* each card.*/
Why/how would I use an abstract method instead of a constructor? The professor said that the abstract method is supposed to call the constructor method, but than.... what is the return type? Something about this assignment just isn't clicking for me...
any suggestions/explanations? Please no solutions...
Re: noob question on abstract classes
The question is essentially asking to write classes which follow what is called the "Template Design Pattern". It allows one to abstract an algorithm, where the abstract class provides the structure and subclasses implement the algorithm (through the implementation of the abstract methods). Google this phrase and you will pull up many upon many examples of this technique.