I was gonna spend my lunchtime having a look at abstract classes / methods in Lucee 5 ("Abstract/Final components/functions"), but... well it didn't work out.
Update:
It is important to note that Micha jumped on the case with this situation straight away, and it is now fixed in Lucee 5.0.0.43. I was testing on .42. It was fixed in less than 24 hours, and that is very impressive. Keep up the good work, Lucee Team.So it's import to note that all the code in this article now works fine, despite the comments to the contrary that I make.
Initially I came up with this example, which is fairly predictable:
// Shape.cfc
abstract component {
abstract numericfunction calculatePerimeter();
public numeric function getSides(){
return variabes.sides;
}
}
// Circle.cfc
component extends=Shape {
variables.sides = 1;
public numeric function init(required numeric radius){
variables.radius = arguments.radius
}
public numeric function calculatePerimeter(){
return pi() * (radius^2)
}
}
// circle.cfm
circle = new Circle(10)
echo ("Circumference: #circle.calculatePerimeter()#<br>")
This defines an abstract component which requires a
calculatePerimeter()
function to be implemented. And then a concrete implementation of that, Circle, which does indeed implement calculatePerimeter()
. And a test rig. This was the result:I messed around as much as I could, and it simply didn't work. If I removed all the abstract-specific stuff, it worked fine, so clearly my code is OK; it's Lucee's code that ain't.
I didn't give up. I grabbed the code from their docs and implemented that:
// AContext.cfc
abstract component {
abstract function getFile();
final function getDirectory() {
return getDirectoryFromPath(getFile());
}
}
// Impl.cfc
component extends=AContext {
function getFile(){
}
}
// impl.cfm
o = new Impl();
Same error. So I have concluded it simply doesn't work. Ticket raised: LDEV-254.
This is, so far, very subpar work for what I expect from those who formerly worked on Railo. I'm now going to treat this work as an alpha in my head. And my advice is that it seems too early to really try it out yet. This is a shame for something that is supposed to be released in May, as well as by a team who used to release very solid work.
--
Adam