Question

I am struggling to extend the android.hardware.Camera class. My problem is that when I try to call the constructor I am having problems with the visibility. So I am wondering whether it is possible at all to do something like this:

import android.hardware.Camera

public class MyCamera extends Camera {

    public MyCamera(Context context) {
        super(context);
    }
}
Was it helpful?

Solution

it would make the code much more understable and less complex

There are many ways to have an API that is "more understandable and less complex". Those objectives do not require inheritance. In some cases, inheritance may be a way to achieve those objectives, but inheritance is not the only solution. And, in some cases, like this one, inheritance has its own issues.

For instance: When trying to zoom you have to first update the camera parameters with the zoom value and then set the camera parameters to the camera. In my own camera object, I then would be able to implement something like camera.zoom();

Use composition.

composition is what I am doing right now. But I feel that there has to be somthing better

Since here is no constructor for Camera that is part of the Android SDK, you do not have much of a choice in the matter, if you want reliable code.

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