I have 3 types of objects: Red, Green, and Blue. I have 3 kinds of devices that handle each type of object, respectively. No device can handle more than 1 type of object. Each "object handler" has a reference to an object which it is currently handling.
In Java I'd do something like this:
public class RedObject {}
public class GreenObject {}
public class BlueObject {}
public class AbstractHandler<T> {
public T myObject;
}
public class RedHandler extends AbstractHandler<RedObject> {}
public class GreenHandler extends AbstractHandler<GreenObject> {}
public class BlueHandler extends AbstractHandler<BlueObject> {}
Is there any non-horrible way to do this in a language without generics? I don't want to define the myObject
property separately on each subclass since then I lose the advantage of inheritance.
(If it helps, the language I'm trying to do this in is actionscript 3.)