´ÙÇü¼º (Polymorphism)
´ÙÇü¼º (Polymorphism)
- ´ÙÇü¼º
- The ability of two or more classes to respond to the same message, each in its own way.
- move(int x, int y); for Polygon and Circle
- print( ); for TextFile, GraphicFile and WordProcessorFile
- Objects of a variety of different, but similar, classes can recognize some of the same messages and respond in similar, appropriate ways.
- ¸Þ¼¼Áö¿Í ¸Þ¼Òµå °£ÀÇ ±¸º°
- Different methods could make sense for a message, but the
sender simply send the message without being concerned with the class of the receiver.
- C++¿¡¼ÀÇ Overloading
- ÇÔ¼ö Áߺ¹¼º (Function Overloading)
- ¿¬»êÀÚ Áߺ¹¼º (Operator Overloading)
Notes:
- Usage
- Better structured & readable pgms
- Debugging, Garbage Collection, Simulation, etc.
- Example in C++
- Class debuggable {
public:
virtual void dump ( ) = 0;
};
- Class X : public debuggable {
int i, j, k;
public:
X (int ii = 0; int jj = 0, int kk = 0) {
i = ii; j = jj; k = kk;
}
void dump ( ) {
cout << "i = " << i
<< "j= " << j
....