В языке Eiffel список наследования помещается вслед за ключевым
словом inherit: class ITEM
export
cut, move, pick, ungroup
feature
cut is deferred end;
move (deltax, deltay: REAL) is deferred end;
pick (x, y: REAL): BOOLEAN is deferred end;
ungroup () is deferred end
class SHAPE
export
cut, draw, erase, move, pick, ungroup, write
inherit ITEM
feature
* x, y: REAL;
cut is <body> end;
draw is <body> end;
erase is <body> end;
move (deltax, deltay: REAL) is <body> end;
pick (x, y: REAL): BOOLEAN is <body> end;
ungroup is <body> end;
write (acolor: COLOR) is deferred end;
end
classrBOX
export pick, write
inherit SHAPE redefine pick, write
feature
width, height: REAL;
Create (x0, y0, width0, height0:*REAL) is <body> end;
pick (x, y: REAL): BOOLEAN is <body> end;
write (acolor: COLOR) is <body> end
end
class CIRCLE
export pick, write
inherit SHAPE redefine pick, write
feature
radius: REAL;
Create (x0, y0, radius0: REAL) is <body> end;
pick (x, y: REAL): BOOLEAN is <body> end;
write (acolor: COLOR) is <body> end
end
Для обозначения абстрактных операций используется ключевое
слово deferred; такие операции должны быть реализованы во всех подклассах.
Переопределение свойств класса в подклассе отмечается в разделе redefine.
В языке Smalltalk описание класса Item, его подкласса Shape, а
также подклассов Box и Circle класса Shape может иметь следующий вид: class name Item
superclass Object
class name Shape
superclass Item
instance variables
x
y
instance methods
cut
draw
erase
move: aPoint
ungroup
class name Box
superclass Shape
instance variables
width
height
instance methods
pick: aPoint
write: aColor
class methods
createAt: aPoint width: widthSize length: lengthSize
class name Circle
superclass Shape
instance variables
radius
instance methods
pick: aPoint
write: aColor
class methods
createAt: aPoint radius: radiusSize
Все атрибуты суперкласса доступны всем его потомкам. Все методы
могут быть переопределены в подклассах. Множественное наследование не
поддерживается.
|