Lock Own Classes

This loads the package.
In[1]:=
Click for copyable input
Having put a lot of effort in your own classes, you might wish to hide the functionality from inquisitorial looks. This is not a problem as long as you keep in mind that, once fully protected, Mathematica does not allow to change the class. Assignments to fields are still possible. Let us look at an example to see how this works. First a "normal" set of classes is defined. Definitions are identical for all, the attributes are different and cover different levels of protection. The class base will allow to check effects on inheritance below.
In[2]:=
Click for copyable input
The obtainable information on the class is quite restricted, if the class has the attribute ReadProtected.
On the other hand, other functions can be used to retrieve the definition.
In[5]:=
Click for copyable input
Out[5]//Short=
Sealing the class' definition is easily achieved by means of the Locked attribute.
In[6]:=
Click for copyable input
The definitions cannot be read out anymore, if the symbol has attribute ReadProtected.
Access to the class is almost not restricted. If a method (constructor included) and a global function have the same name and the function symbol has attribute Locked, the attributes of the global function are used. Objects can be created, members used and fields reassigned.
In[9]:=
Click for copyable input
Out[9]=
A locked class can still be a parent of another class. The next cell shows some examples.
In[10]:=
Click for copyable input
Out[10]=
While the base is locked, the child may be changed. The next cell redefines the classes from above.
In[11]:=
Click for copyable input
Out[11]=
If you do not change the patterns inside base, you may redefine it. Pattern renaming is allowed, because it represents the same pattern.
In[12]:=
Click for copyable input
Out[13]=
Any other redefinition of a parent class of a locked class causes complaints. Whenever a base class is redefined, the dependent classes are regenerated in order to be up to date. Because they are locked, this cannot be done.
Consequently, the derived classes are no longer usable.
In[15]:=
Click for copyable input
Out[15]=