/* ****************************** * Object Oriented Programming in C * * Author: Laurent Deniau, Laurent.Deniau@cern.ch * * For more information, please see the paper: * http://home.cern.ch/ldeniau/html/oopc/oopc.html * ****************************** */ #include /*-----------------------------*/ /* manager implementation */ /* inherit from employee */ /*-----------------------------*/ #define IMPLEMENTATION #include /* --------------------- Object implementation --------------------- */ void constMethodOvldDecl(print, person) { sendCMsg(this, employee, person.print); sendCMsg(super(sub_cast(this,employee.m.person),education),education,print); printf("\tlevel:\t%d\n", sub_cast(this,employee.m.person)->m.level); } OBJECT_IMPLEMENTATION SUPERCLASS (employee), SUPERCLASS (education) ENDOF_IMPLEMENTATION /* -------------------- Class implementation -------------------- */ initClassDecl() /* required */ { /* initialize super class */ initSuper(employee); initSuper(education); /* overload super class methods */ overload(employee.person.print) = methodOvldName(print, person); /* default level */ objDefault(level) = 1; } dtorDecl() /* required */ { employee._employee(super(this,employee)); education._education(super(this,education)); } t_manager classMethodDecl_(*const new) char const name[], char const department[], char const diploma[], int level __ { t_manager *const this = manager.alloc(); if (this) manager.init(this, name, department, diploma, level); return this; } void methodDecl_(init) char const name[], char const department[], char const diploma[], int level __ { employee.init(super(this,employee), name, department); education.init(super(this,education), diploma); this->m.level = level; } void methodDecl_(copy) t_manager const*const mng __ { manager._manager(this); manager.init(this, mng->m.employee.m.person.m.name, mng->m.employee.m.department, mng->m.education.m.diploma, mng->m.level); } CLASS_IMPLEMENTATION methodName(new), methodName(init), methodName(copy) ENDOF_IMPLEMENTATION