且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有可能延长Android相机类?

更新时间:2023-11-10 16:25:16


  

这将使code更understable并不太复杂的


块引用>

有很多方法可以有一个API,它是更容易理解,更简单。这些目标并不需要继承。在某些情况下,遗产可能的方式来实现这些目标,但继承不是唯一的解决办法。并且,在某些情况下,像这样的,继承有它自己的问题。


  

例如:当试图放大你必须先更新变焦值的相机参数,然后设置相机参数相机。在我自己的相机对象,然后我将能够实现类似camera.zoom();


块引用>

使用成分。


  

成分就是我现在做的事情。但我觉得必须有更好的财产以后


块引用>

由于这里是相机是Android SDK的一部分,没有构造函数,你没有多少选择的余地在这个问题上,如果你想可靠$ C $角

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

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.