Apr 9.polymorphism2

Apr 9.polymorphism2 - Abstract Classes and Concrete Classes...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Abstract Classes and Concrete Classes An abstract class is one for which you never intend to instantiate any objects – abstract classes are normally “incomplete” – the derived classes have to fill in the missing parts – abstract classes normally have one or more pure virtual methods Abstract classes do have to specify prototypes for their methods, but there is no definition for any pure virtual functions The whole purpose of an abstract class is to serve as a base class for other objects A concrete class is one for which you can instantiate objects – to be concrete, a derived class has to override all pure virtual methods of a base class
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Abstract Classes and Polymorphism We can’t instantiate objects of an abstract class, but we can declare pointers of abstract-class type These pointers can point to an object of any concrete class that is derived (directly or indirectly) from the abstract class Programs can then use these base-class pointers to manipulate instances of the derived classes using polymorphic methods Let’s walk through the principle again with Deitel’s payroll system example This is a CLR example (the one last time was a standard C++ example)
Background image of page 2
Payroll System Case Study • A company has several classes of employees: – Boss (paid a weekly salary independent of how many hours he works) – Commission (paid a flat base salary plus a percentage of the sales generated by this employee) – Hourly (paid an hourly wage plus time and a half for overtime) – Piece (paid on the basis of how many pieces produced) • The payroll application has to determine the weekly pay for employees regardless of what category of employee they are – different classes of workers have their pay computed differently
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Payroll System Case Study (cont.) Define an abstract class Employee – declare a pure virtual method in Employee virtual Decimal Earnings() = 0; – the initializer =0 makes this a pure virtual method
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/30/2008 for the course EE 361 taught by Professor Conry during the Spring '08 term at Clarkson University .

Page1 / 13

Apr 9.polymorphism2 - Abstract Classes and Concrete Classes...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online