components can do A LOT of stuff, they can be used for Soap, Rest, Hibernate and (with Lucee 6) web socket interactions. In addition they allow code injection, extend other components and implement interfaces at runtime and many more stuff.
Problem is that every component has the burden to support all of this, even it does not do it.
We changed in Lucee 6 how a component is setup, so it not always comes with all features out of the box.
If a component for example does not extend any other component, Lucee does setup it differently. If a component does not get code injected it works differentlyâŠ
Of course the only different for the user is, that the component get faster.
This is a great start, but still comes with limitation, because Lucee is a dynamic language.
So the idea wa born for âBeansâ. The most stupid and simple component you can think of, a mix between components and struct.
So how does a Bean look like
// Person.cfc
bean {
property string firstName;
property string middleName;
property string lastName;
function getLastName() {
if(isNull(this.lastName)) return "NoName";
return this.lastName;
}
}
// index.cfm
person=new Person();
person.firstName="Susi";
person.lastName="Sorglos";
dump(person.firstName&" "&person.lastName):
A bean can only define properties and getters and setters to this properties. It cannot extend or implement components or interface (maybe other beans?). It has no variables scope, only the private this scope. functions defined must be public.
From outside it only has the Struct interface, so you cannot call functions.
All this limitation makes it possible to make them very fast and much less memory consuming.
The idea is also that you can define a bean as a return type for a query
query name="persons" returntype="Person" {
echo("select firstname,middlename,lastname from person");
}
dump(persons);
Benefit with this over struct as a return type, you can pass along that Person array and you do not have to check if firstname exists when you use it.
When you convert to a json string it will create
{'firstName':"Susi",'lastname':"Sorglos"}
What do you think, useful , useless or i donât care?