ZBasic Language Reference
116
ZBasic Microcontrollers
Including one or more other classes as mixins of a given class is accomplished using the Includes
keyword as shown in the example below. If more than one mixin class is specified, the mixin class names
are comma-separated.
Class A
Public:
Sub DoSomething()
End Sub
Protected:
Private:
End Class
Class B Includes A
Public:
Sub Identify()
Call DoSomething()
End Sub
End Class
Dim MyB as B
Sub Main()
Call MyB.DoSomething()
End Sub
One restriction on using mixins is that the public and protected methods and data members of each mixin
must be unique among all of the mixins included and must not duplicate any method or data member
names of the including class. This restriction is necessary because all public and protected methods and
data members need to reside in the namespace of the including class and therefore must be unique. It is
possible, however, to have methods of the same name in multiple mixins and/or the including class as
long as they each have unique signatures, i.e. they must have different number and/or types of
parameters. Note, however, that the including class may contain methods that overload methods of mixin
classes. It is important to be aware that a mixin class method that is marked as Abstract must be
overloaded by the including class.
Finally, if a class is defined using both inheritance and mixins, the Extends <class name>
specification must appear before the Includes <class name list> specification, e.g.
Class D Extends B Includes A, C
Public:
Sub DoSomething()
End Sub
End Class
In rare cases, it is useful or necessary to be able to refer to the mixin element or its data members or
methods as if they were made part of the containing class by composition. For this purpose, a member
name for the mixin class element is automatically provided by the compiler consisting of the mixin class
name with _Mixin_ preceding it. For example, for a mixin class A the automatically created member
name is _Mixin_A. Consequently, a public method of mixin A can be referred to using either of the
following:
Call DoSomething()
Call _Mixin_A.DoSomething()
The two methods above are equivalent so there is no advantage to using the second, more verbose,
option. However, if you want the address of the mixin element, the only way to achieve that goal is to use
the prefixed name:
@_Mixin_A
|