# 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
