namespace FreeDlder
{
// 抽象类
public abstract class Dld
{
protected Form1 mainGui;
protected String id;
protected Boolean isStop = false;
protected int completed = 0;
protected String filename;
protected String url;
// 抽象类构造函数
public Dld(Form1 mainGui, String id, String filename, String url)
{
this.mainGui = mainGui;
this.id = id;
this.filename = filename;
this.url = url;
}
// 抽象类的抽象函数
public abstract void run();
public void setStopped()
{
isStop = true;
}
public void setStarted()
{
isStop = false;
}
public String getID()
{
return id;
}
}
以上和Java抽象类没啥分别,但实现类有特殊的语法,如下:
public class HttpDld : Dld // 子类的继承,相当于java的extends
{
// 子类调用父类的构造函数,作用与java的super()类似,但写法大相径庭
public HttpDld(Form1 mainGui, String id, String filename, String url)
: base(mainGui, id, filename, url)
{
}
// 实现父类的抽象方法,但比Java多了一个override语法
public override void run()
{
////
}
}
}