Question

I have two classes, ImageMap, extending ImageView and PageView extending GLSurfaceView, I am using the ImageMap to mainly have hot spots on drawables but I also need to add a page flip/curl animation to it, in order to do that I need those two classes to act as one object, any idea how to do that?

It is totally clear to me that multiple inheritance is not allowed in java.

Was it helpful?

Solution

There is no way of really extend two classes. What you can do is:

  1. You make a wrapper object, that holds one instance of each object. and simply do this.ImageMap.filed1 and so. This is more convenient while developing the class. This also allows you to proxy method invocations.
  2. You define interfaces which should be implemented, and you make a new class which implements both. This is only for class that use this class to have the interface, without really caring about the implementation.

You may need both things, since the first is about "how to do it" and the second about "how it will be presented to objects that use it".

OTHER TIPS

Your question is not about Android; it's about Java.

Java does not allow for multiple inheritance.

Your reasoning is inaccurate regarding the following:

in order to do that I need those two classes to act as one object

That's not the case. An 'Activity', for example, does not have to be an event handler; it's enough if your 'Activity' can have an event handler, e.g. as an inner class which can access the Activity's variables.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top