I currently have a register template that defines a method called read_action that I am looking to deprecate. I'd ideally like to decorate this method in the base template in such a way that no other template or register/field that imports this template can define read_action() and cause a compiliation error if they do. In C++ I could have achieved this by decorating it with the final keyword in C++.
template my_read is (read) {
shared method read_action(uint64 in_value) -> (uint64) throws default {
return in_value;
}
}
Is there any equivalent to final in DML?
DML methods are final by default, so the direct equivalent of your C++ trick would be to just remove the
default
keyword:Since this method is not default, any attempt to override will give a compile error; furthermore, any call to the method will give an error in run-time.
A further improvement is to just poison the symbol
read_action
:This gives compile-time errors both for overriding and using the symbol. Furthermore, the DMLC error message of an override will point out this line, making the comment a complementary error message.
This trick is in fact employed for some esoteric symbols in the DML 1.2 standard library (e.g.
dev.banks
,dev.log_group
), that were deprecated for DML 1.4.