Tuesday, February 17, 2009

Ch7, Ex2

Make a functor to represent the package as follow:
functor
export
%export the all defined classes
a:A
%......
define
%create names for all the protected methods
P1 = {NewName}
%......

%all the above created names are available to *any*
%class inside this functor(or say package)

class A
%put all protected method as a record
%inside an attribute
attr setOfAllProtectedMethods:p(p1:P1)

meth init
skip
end

meth !P1(?Msg)
Msg='I am protected'
end
end

%......
end
This is how a class inheriting A can access protected methods.
%Create an instance of above functor, bind it to an
%identifier, lets call it TestPackage. Then this is how protected
%method P1 in class A can be used from a class inheriting it.
declare
class B from TestPackage.a
meth callP1(Msg)
P1 = (@setOfAllProtectedMethods).p1 in
{self P1(Msg)}
end
end

%Test
local O in
O = {New B init}
{Browse {O callP1($)}}
end

No comments:

Post a Comment