summaryrefslogtreecommitdiffstats
path: root/doc/scriptexamples/class1.kvs
blob: 6098000dd3e76f6ca9c5b806fcd603721d33ff56 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Example of object function overriding and calling
# This is quite intricated...try to get out of this
# by examining the code.

class (A,object)
{
	# The base class at all
	# Implements $A::function and $A::virtual
	function
	{
		echo -i=10 "$0\Entering A::function()"
		$$->$virtual("----$0")
		echo -i=10 "$0\Exiting A::function()"
	}
	virtual
	{
		echo -i=10 "$0\This is A::virtual()"
	}
}

class (B,A)
{
	# Derived from A : inherits $A::function()
	# overrides $A::virtual
	virtual
	{
		echo -i=20 "$0\Entering B::virtual()"
		$$->$A::virtual("----$0")
		echo -i=20 "$0\Exiting B::virtual()"
	}
}

class (C,B)
{
	# Derived from B : inherits $B::virtual and 
	# overrides $B::function (that is $A::function)
	function
	{
		echo -i=30 "$0\This is C::function"
	}
}

echo -i=7 "Ok...now try to gusess what's going on :)"

%o = $new(C,0,test)

echo "# Calling \%o->\$function"
%o->$function
echo "# Calling \%o->\$C::function"
%o->$C::function
echo "# Calling \%o->\$B::function"
%o->$B::function
echo "# Calling \%o->\$A::function"
%o->$A::function
echo "# Implementing private \%o->\$function"
privateimpl(%o,function)
{
	# This is a private implementation that
	# overrides $C::function
	echo "$0\Entering \$\$::function"
	$$->$C::function("----$0");
	echo "$0\Exiting \$\$::function"
}

echo "# Calling \%o->\$function"
%o->$function
echo "# Calling \%o->\$C::function"
%o->$C::function
echo "# Calling \%o->\$B::function"
%o->$B::function
echo "# Calling \%o->\$A::function"
%o->$A::function
echo "# Implementing private \%o->\$virtual"
privateimpl(%o,virtual)
{
	# This is a private implementation that
	# overrides $C::virtual (that is $B::virtual in fact)
	echo "$0\Entering \$\$::virtual"
	$$->$C::virtual("----$0")
	echo "$0\Exiting \$\$::virtual"
}

echo "# Calling \%o->\$function"
%o->$function
echo "# Calling \%o->\$C::function"
%o->$C::function
echo "# Calling \%o->\$B::function"
%o->$B::function
echo "# Calling \%o->\$A::function"
%o->$A::function
echo "# Removing private \%o->\$function"
privateimpl(%o,function){}
echo "# Calling \%o->\$function"
%o->$function
echo "# Calling \%o->\$C::function"
%o->$C::function
echo "# Calling \%o->\$B::function"
%o->$B::function
echo "# Calling \%o->\$A::function"
%o->$A::function

delete %o