So if you have a polymorhic array, you do not (exactly) know from which classes the elements will be instances. However, if you know all of those classes implement or inherit a certain method, you can call that method on each of the elements and php will use the proper implementation.
An easy way to prevent the calling of a method on an object that does not implement or inherit it is limiting the objects to be of a certain type. For example instances of a class or its subclasses. Then by only calling methods that are defined by the type, one is sure that all objects will at least have the inherited method. If we talk in the context of phpPeanuts about a polymorphism and a type, we generally mean instances of a class and its subclasses.
As phpPeanuts uses normal php classes and methods, polymorphism is generally there. In the phpPeanuts component model it is furtermore supported by the "ïnheritance" of class descriptor features and propertyDescriptors.
As of version 1.1. is supported. If persistency is polymorphic, the for peanuts will automatically retrieve objects of the proper subclass. Be aware that if you override the default behavior by writing a getter method, you may have to take care of this yourself.
The user interface can handle polymorphic types, but has some limitations:
- SearchPages will by default only offer search options from the type itself, not from subtypes. If you want to include search options from subtypes, you will have to override its search options list and code the adding of the extra options yourself.
- In general Page and Part specialization by creating a class whose name includes the type (like EmployeeEditDetailsPage for Employee) is only used for the specific type, not for its subtypes. So if you have one abstract superclass with three concrete subclasses you want to specialize for, you will need three page classes, one for each subclass. And if the page is targeted to multiple objects (IndexPage, SearchPage, SelectionReportPage and ObjectDialog), you may have to add another page for the abstract superclass. We are working on a way to allow you to override this specialization behavior, but for the moment that is "not analyzed yet".
|