in reply to Problems I've had with array based objects
package Node; use constant FIRST_IDX => 0; use constant IDX_PARENT => FIRST_IDX + 0; use constant NEXT_IDX => FIRST_IDX + 1;
package ElementNode; BEGIN { our @ISA = 'Node'; } use constant FIRST_IDX => __PACKAGE__->SUPER::NEXT_IDX(); use constant IDX_NAME => FIRST_IDX + 0; use constant IDX_ATTS => FIRST_IDX + 1; use constant NEXT_IDX => FIRST_IDX + 2;
If ElementNode needed to access IDX_PARENT, then I'd either add an accessor or I'd add
use constant IDX_PARENT => __PACKAGE__->SUPER::IDX_PARENT();
If a field needs to be added, only the indexes in the class where the field needs to be added are changed.
package Node; use constant FIRST_IDX => 0; use constant IDX_PARENT => FIRST_IDX + 0; use constant IDX_ISROOT => FIRST_IDX + 1; use constant NEXT_IDX => FIRST_IDX + 2;
This doesn't support multiple inheritance, but it does support traits and (java-like) interfaces. As said by Steve Cook, "Multiple inheritance is good, but there is no good way to do it."
|
|---|