Implementations
Implementation types exhibit a very similar behavior to traits. They provide chunks of methods that a class can reuse.
An implementation models the following properties:
- The required attributes the class must have
- The required interface the class must implement
- The methods that the class will have once the implementation is applied
In this, any class that implements the Object3D interface must implement a lot of methods, which is very reptitive if a lot of classes exhibit the same behavior. This is where implementations come in.
One can refactor this into an ECS-like system, or, use implementations to reduce the amount of code needed.
In this example, we have created an implemtation, where the class must have the position, rotation, and scale attributes, and the Object3D interface.
The Implementation Default3DPropsAccessImpl essentially provides parameterized methods that the class can use. The parameters are the attributes required by the implementation, which can be passed in the impl statement within the class
Overriding Implementations
The methods provided by an implementaiton to a class, are considered external methods. You can override their behavior using override keyword:
When you override a method, it needs to match against an external method, otherwise the compiler will throw an error.
An example of implementations is found in tests/test19: