I believe it's enough to have [Final] keyword set in deployed mode to give a developer a hint that this class should not be extended.
Well, it's mainly for developers who can't take a hint.
If you want to enforce this behaviour, I would add a check into each method as a first line , something like
if $this.%ClassName(1)'="My.Class" quit $$$ERROR(50000,"don't extend this class")
Good idea.
You can also try to add a method-generator, I believe when you have a deployed class with method generator it will not be able to compile a subclass without method generator's source (though I'm not sure).
At first it didn't work - method generator by default works while deployed. Then I added a class check to generator. Compilation was now failing, but other methods were actually compiled so I was able to call them. Finally I worked out this solution:
Class Package.Final [ Final ]
{
ClassMethod ANoExtend() [ CodeMode = objectgenerator, Final, ForceGenerate, Private ]
{
quit:%class.Name="Package.Final" $$$OK
quit $$$ERROR($$$GeneralError, "No extending")
}
ClassMethod ProtectedMethod() As %Status [ Private, ForceGenerate, GenerateAfter = ANoExtend ]
{
// code
quit $$$OK
}
}This way each protected method should be recompiled but only after method-generator which always fails in subclasses. This way no code gets generated.
- Log in to post comments


