2.多媒体播放对象 回到上节的问题,我们在开发多媒体播放器时,希望可以采用RealPlay和 MS MediaPlay两种播放器。而二者的接口完全不同,并且我们可能在将来引入其他播放器。
为了使程序兼容两种播放器,我们定义了一个播放器的接口。然后用两个适配器分别实现这个接口,并调用RealPlay和 MS Media Player的API,这是典型的对象适配器。
采用对象适配器的结构如图所示。
代码如下:
'播放器的接口 PublicInterface AudioPlayerInterface AudioPlayer Sub DoPlay()Sub DoPlay() Sub DoStop()Sub DoStop() Sub DoPause()Sub DoPause() Property Source()Property Source() AsString End Interface '采用Real Player API的播放器 PublicClass RealAuidoPlayerClass RealAuidoPlayer Implements AudioPlayer Private mAP As AxRealAudioObjects.AxRealAudio PublicSub New()SubNew(ByVal c As Control) mAP =New AxRealAudioObjects.AxRealAudio c.Controls.Add(mAP) mAP.Visible =False End Sub PublicSub DoPause()Sub DoPause() Implements AudioPlayer.DoPause mAP.DoPause() End Sub
PublicSub DoPlay()Sub DoPlay() Implements AudioPlayer.DoPlay mAP.DoPlay() End Sub
PublicSub DoStop()Sub DoStop() Implements AudioPlayer.DoStop mAP.DoStop() End Sub
PublicProperty Source()Property Source() AsStringImplements AudioPlayer.Source Get Return mAP.Source EndGet Set(ByVal Value AsString) mAP.Source = Value EndSet End Property End Class
'采用MS Media Player 的播放器类 PublicClass MediaPlayerClass MediaPlayer Implements AudioPlayer Private mAP As WMPLib.WindowsMediaPlayerClass Private ms AsString
PublicSub New()SubNew() mAP =New WMPLib.WindowsMediaPlayerClass End Sub
PublicSub DoPause()Sub DoPause() Implements AudioPlayer.DoPause mAP.pause() End Sub
PublicSub DoPlay()Sub DoPlay() Implements AudioPlayer.DoPlay mAP.play() End Sub
PublicSub DoStop()Sub DoStop() Implements AudioPlayer.DoStop mAP.stop() End Sub
PublicProperty Source()Property Source() AsStringImplements AudioPlayer.Source Get Return mAP.URL EndGet Set(ByVal Value AsString) mAP.URL = Value mAP.pause() EndSet End Property End Class
采用类适配器的结构如图所示。
以RealPlay为例,代码如下:
1'采用Real Play API的播放器类,类适配器 2PublicClass RealAudioPlayerClassClass RealAudioPlayerClass 3Inherits AxRealAudioObjects.AxRealAudio 4Implements AudioPlayer 5 6PublicSub New()SubNew(ByVal c As Control) 7 c.Controls.Add(Me) 8Me.Visible =False 9End Sub 10 11PublicSub DoPause()Sub DoPause() Implements AudioPlayer.DoPause 12MyBase.DoPause() 13End Sub 14 15PublicSub DoPlay()Sub DoPlay() Implements AudioPlayer.DoPlay 16MyBase.DoPlay() 17End Sub 18 19PublicSub DoStop()Sub DoStop() Implements AudioPlayer.DoStop 20MyBase.DoStop() 21End Sub 22 23PublicProperty Source()Property Source() AsStringImplements AudioPlayer.Source 24Get 25ReturnMyBase.Source 26EndGet 27Set(ByVal Value AsString) 28MyBase.Source = Value 29EndSet 30End Property 31End Class 32
好久不来iteye,今天又来看看,哈哈,今天碰到在编码时,反射中会抛出
Illegal overloaded getter method with ambiguous type for propert这么个东东,从字面意思看,是反射在获取getter时迷惑了,然后回想起java在boolean值在生成getter时,分别有is和getter,也许我们的反射对象中就有is开头的方法迷惑了jdk,
泛型
在Java SE 1.5之前,没有泛型的情况的下,通过对类型Object的引用来实现参数的“任意化”,任意化的缺点就是要实行强制转换,这种强制转换可能会带来不安全的隐患
泛型的特点:消除强制转换 确保类型安全 向后兼容
简单泛型的定义:
泛型:就是在类中将其模糊化,在创建对象的时候再具体定义
class fan
安装lua_nginx_module 模块
lua_nginx_module 可以一步步的安装,也可以直接用淘宝的OpenResty
Centos和debian的安装就简单了。。
这里说下freebsd的安装:
fetch http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar zxvf lua-5.1.4.tar.gz
cd lua-5.1.4
ma
public class IsAccendListRecursive {
/*递归判断数组是否升序
* if a Integer array is ascending,return true
* use recursion
*/
public static void main(String[] args){
IsAccendListRecursiv
function init() {
var tt = document.getElementById("tt");
var childNodes = tt.childNodes[0].childNodes;
var level = 0;
for (var i = 0; i < childNodes.length; i++) {
在安装hadoop时,执行JPS出现下面错误
[slave16][email protected]:/tmp/hsperfdata_hdfs# jps
Error occurred during initialization of VM
java.lang.Error: Properties init: Could not determine current working