Hey Gary,
Sorry, my last example was incomplete - you would also need to have
those base class values in your Player init() (see more complete
example below).
If you're using implicit accessors anyway, you can skip the whole
init() routine altogether and not have to call super - these two
classes would wire together perfectly with the Player class extending
the base class and both containing only accessors="true" and the
properties (see second example below).
If you're using 9.0.1 you can take advantage of mappedSuperClass to
map a (non-persistent) base class to persistent child classes to share
functionality (see 3rd example below)
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e0e.html
links to the cfcomponent tag in the CF9 livedocs - it's a good read
and will explain more about the options available to you. There's also
a great deal of info in the developers guide for 9 that speaks to this
topic and might also be a good read. Also, Object-Oriented Programming
in ColdFusion book has a small subset on inheritance and the use of
super.
In any case, the following ought to work even with implicit accessors
(though I didn't test it, so don't hold me to it):
component displayname="Player" extends="model.beans.User"
accessors="true" output=false {
property name="jerseyNumber" type="string";
public model.beans.Player function init(string jerseyNumber=',
string firstName='', string lastName=''')
output=false {
<!--- SUPER THE BASE CLASS --->
super.init(firstName = arguments.firstName, lastName =
arguments.lastName);
setJerseyNumber(arguments.jerseyNumber);
return this;
}
}
And the alternative should be something along the lines of:
component displayname="User" accessors="true" output=false {
property name="firstName" type="string";
property name="lastName" type="string";
}
component displayname="Player" extends="model.beans.User"
accessors="true" output=false {
property name="jerseyNumber" type="string";
}
Calling Player.getFirstName() will return the value stored with a
Player.setFirstName(). No init() needed.
And, finally, using a non-persistent (not ORM) base class with a
persistent (ORM + accessors = true) class:
component displayname="Player" extends="model.beans.User"
accessors="true" mappedSuperClass="true" output=false {
property name="jerseyNumber" type="string";
}
In which case your base class should not be persistent (accessors =
false) - CF will create the accessors and wire them to any components
which share the base class when using mappedSuperClass="true" with an
ORM (persistent) application.
Hope this is more helpful - was a bit rushed unexpectedly earlier and
wanted to circle back and try and clarify the options ;)
-- Denny