Hi, I noted that FPodNamespace initialises itself too soon to be of use for subclasses.
new make(File? dir) {
this.dir = dir
init // <-- this line!
}
protected override FPod? findPod(Str podName) {
...
}
This issue is that init() (indirectly) calls the overridden findPod() before a subclass has a chance to initialise itself.
class MyNs : FPodNamespace {
private FPod fpod
new make(FPod fpod) : super.make(null) {
// this is only called AFTER super.make()
this.fpod = fpod
}
override FPod? findPod(Str podName) {
// this is null, becasue the ctor code hasn't been called yet
return fpod
}
}
I do have a workaround for now - but it'd be nice if that call to init() was moved out of the ctor.
brianThu 29 Dec 2022
That class really isn't designed to be subclassed since it is trying to obey the CNamespace design. Moving init out of make would leave the instance incomplete.
It might be better to subclass directly from CNamespace and handle the the findPod yourself?
SlimerDudeSat 31 Dec 2022
Hi Brian,
Thanks for the quick reply.
I guess I was hoping that it would only have been a quick refactor in a couple of places to replace:
fpod := FPodNamespace() // <-- calls super.init()
with:
fpod := FPodNamespace().init() // <-- just calls init()
But if the FPodXxx classes weren't meant to be extended, I can keep using my workaround.
SlimerDude Thu 29 Dec 2022
Hi, I noted that FPodNamespace initialises itself too soon to be of use for subclasses.
This issue is that
init()
(indirectly) calls the overriddenfindPod()
before a subclass has a chance to initialise itself.I do have a workaround for now - but it'd be nice if that call to
init()
was moved out of the ctor.brian Thu 29 Dec 2022
That class really isn't designed to be subclassed since it is trying to obey the CNamespace design. Moving init out of make would leave the instance incomplete.
It might be better to subclass directly from CNamespace and handle the the findPod yourself?
SlimerDude Sat 31 Dec 2022
Hi Brian,
Thanks for the quick reply.
I guess I was hoping that it would only have been a quick refactor in a couple of places to replace:
with:
But if the
FPodXxx
classes weren't meant to be extended, I can keep using my workaround.Happy New Year! :)
Steve.