One concept which I have given some thought to, but which I've never seen addressed in any existing language which I know of, is the possibility of an object temporarily belonging to a category. PredicateTypes, maybe? To give a real world example, a person may join the Army, and for the duration of their enlistment be classified as a soldier; but before enlistment, and after mustering out, they would no longer be a soldier. To further break it down, a soldier can be an enlistee, an NCO, or an commissioned officer (USAian terms, as I know them; insert the correct terminology for different nations), and may have a given rank within those categories. Both rank and category may change over their time in the military; yet when they are no longer in the military, they would no longer have those qualities at all (though career officers often keep their rank after retiring).
Now, the conventional approach would be to create a class Person, and a subclass Soldier, instantiate the individual as a Soldier, and then upcast them back to Person afterwards, ignoring the 'extra' attributes. This doesn't seem quite satisfactory, however; It treats the soldier as a different type of person from a 'default' civilian, rather than as a Person who has temporarily gained, lost or changed certain attributes. Nonetheless, it is clearly a case where a category, with common properties and inheritance of type, is involved.
I have never seen this sort of temporary categorization (which I've termed a 'role') addressed in either patterns or language constructs, yet it seems to be an obvious issue. Does anyone know what work, if any, has been done on this topic?
A parallel issue exists in composition, where an object may have a component which is added on after it's creation, even if it might not have been designed for it; consider the various modifications possible to automobiles, many of which are unique and could not have been anticipated by the original designers. Unlike roles, these 'customizations' are specific to a given object, and do not represent a category with shared attributes. While a permanent customization can be easily deal with (especially in a prototype based language, as you can simply change the single object alone), the case of a temporary customization presents the same issues as mentioned above with roles. Again, I was curious as to what work, if any, has been done to deal with this issue.
Something like StatePattern might be the ticket.
DynamicInheritance?, a la SelfLanguage, is also a way of achieving this. PredicateClasses (in CecilLanguage) is something similar, if you can formalize the constraints for switching "roles" fully. -- JonathanTang