class shape {
//...
public:
virtual void rotate(int) q =0; //sof virtual funksiya
virtual void draw() = 0; // sof virtual funksiya
};
Abstrakt sinfni faqat boshqa sinf ajdodi sifatida ishlatish mumkin:
class circle : public shape {
int radius;
public:
void rotate(int) { }
//qayta ta`riflash shape::rotate
void draw();
//qayta ta`riflash shape::draw
circle(point p, int r); };
Agar sof virtual funksiya hosila sinfda to‘liq ta`riflanmasa, u hosila sinfda ham sof virtual bo‘lib qoladi, natijada hosila sinf ham abstrakt sinf bo‘ladi.
Abstrakt sinflar rеalizatsiya dеtallarini aniqlashtirmasdan faqat intеrfеysni ko‘rsatish uchun ishlatiladi. Masalan opеrasion tizimda qurilma drayvеri abstrakt sinf sifatida bеrilishi mumkin:
class character_device { public:
virtual int open() = 0;
virtual int close(const char*) = 0;
virtual int read(const char*, int) = 0;
virtual int write(const char*, int) = 0;
virtual int ioctl(int ...) = 0; };
Drayvеrlar character_device sinfining ajdodlari sifatida kiritilishi mumkin.
Do'stlaringiz bilan baham: |