Is it possible to extend the Android Camera class?

依然范特西╮ 提交于 2019-12-11 04:39:59

问题


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);
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/21501651/is-it-possible-to-extend-the-android-camera-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!