-
Notifications
You must be signed in to change notification settings - Fork 6
/
PilaresPoo.prw
81 lines (63 loc) · 1.78 KB
/
PilaresPoo.prw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "Totvs.ch"
// ----------------------------------------
// Super Classe
// ----------------------------------------
Class Animal
private data cName
private data oOwner as Pessoa
Method New() Constructor
Method move()
Method getName()
Method setOwner()
Method getNameOwner()
EndClass
Method New(cName) Class Animal
::cName := cName
::setOwner(Pessoa():New('Desconhecido'))
Return Self
Method move() Class Animal
Return ' andou'
Method getName() Class Animal
Return ::cName
Method setOwner(oOwner) Class Animal
::oOwner := oOwner
Return
Method getNameOwner() Class Animal
Return ::oOwner:getName()
// ----------------------------------------
// Sub Classe
// ----------------------------------------
Class Peixe From Animal
Method New() Constructor
Method move()
EndClass
Method New(cName) Class Peixe
_Super:New(cName)
Return Self
Method move() Class Peixe
Return ' nadou'
// ----------------------------------------
// Sub Classe
// ----------------------------------------
Class Macaco From Animal
Method New() Constructor
Method move()
EndClass
Method New(cName) Class Macaco
_Super:New(cName)
Return Self
Method move() Class Macaco
Return ' pulou de galho em galho'
// ----------------------------------------
// Exemplo de uso
// ----------------------------------------
User Function ExecPolimorfismo()
Local oAnimal := nil // Tipo Animal
oAnimal := Animal():New('Bob')
oAnimal:setOwner(Pessoa():New('Fernando'))
MsgInfo(oAnimal:getName() + oAnimal:move() + ' até ' + oAnimal:getNameOwner(), 'O animal')
oAnimal := Peixe():New('Nemo')
MsgInfo(oAnimal:getName() + oAnimal:move() + ' até ' + oAnimal:getNameOwner(), 'O peixe')
oAnimal := Macaco():New('Kaco')
MsgInfo(oAnimal:getName() + ' sempre' + oAnimal:move() + ' até ' + oAnimal:getNameOwner(), 'O macaco')
Return