Basic Examples
Import the package:
Basic syntax:
CreateType[TypeName,ParentTypeName,Constructor,{Field1,"Field2",Field3→3,"Field4"→4}]
where:
TypeName is Symbol
ParentTypeName - is Symbol and TypeQ[ParentTypeName] == True
Constructor - any expression that will be applied to TypeName instance like Constructor[instance]
Field# - String or symbol or rule with String or Symbol
Create new type called Human. To set properties for a new type you can use strings and symbols also rules with strings and symbols:
And not we can create some human:
All properties of the human are associated with the symbol Human`$11 (or another unique symbol). You can extract the symbol using following code:
And try to get internal properties:
Also you can extract internal association with special syntax that available for the any type inherited from the Object:
Also you can get property names:
Autocomletion works by default for the symbol associated with the object:
Anoter way to get available property is:
Also you can use this way with internal objects and association. For example let's add the child:
And now Kirill object looks like:
You can get the name of the child:
Also you can set any property:
And now Zlata looks like:
And with associations too:
And set one toy:
And another toy:
And the result:
Define method that will be work only for Human type:
Check this method:
Create new type from Human as parent type:
Create some student:
Check that method sayHi inhered: