是否有可能延长Android相机类? [英] Is it possible to extend the Android Camera class?

查看:140
本文介绍了是否有可能延长Android相机类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我奋力延长 android.hardware.Camera 类。我的问题是,当我尝试调用构造函数我有知名度的问题。所以,我想知道是否有可能在所有做这样的事情:

 进口android.hardware.Camera公共类MyCamera扩展相机{    公共MyCamera(上下文的背景下){
        超级(上下文);
    }
}


解决方案

  

这将使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.

这篇关于是否有可能延长Android相机类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆