実際の例を示します。私は抽象クラス呼び出しcSourceControlを持っています。次に、Visual Source Safe呼び出し用のクラスcVSSと、cSVNと呼ばれるSubversion用のクラスがあります。どちらもcSourceControlから継承されています。
これで、抽象クラスには、継承クラスでちょうど使用できるバンチプロパティとメソッド(コード付き)があります。このことから
public abstract DataTable getFiles(string path, string filter, DateTime since, bool filterAuthorByLastCheckin, bool expandAll, bool onlySinceBranched);
public abstract DataTable getFiles(string path, string filter, DateTime since, string lastUser, bool filterAuthorByLastCheckin, bool expandAll, bool onlySinceBranched);
public abstract long getFile(string sFileName, string sVersion, string sLocalFileName);
public abstract DataTable getFileVersions(string sFileName);
public abstract DataTable getDirectories(string path, bool expandAll);
public abstract DataTable getChangedFiles(string path);
public abstract DataTable GetFileLogRevision(string path, string revision);
public abstract DateTime getBranchStartDateTime(string sBranch);
を使用すると、SourceControlクラスは、これらのそれぞれが必要になりますことを伝えることができますが、それはCVSSで見え方がより非常に異なっている:抽象クラスにも継承されたクラスが実装しなければならない抽象メソッドの束を定義しますそれはcSVNでどのように見えますか?もう一つの利点は、実行時にVSSまたはSVNを選択できることです。単純化されたコードスニップは次のようになります。
cSourceControl sc;
if(usingVSS)
sc = new cVSS();
else
sc = new cSVN();
DataTable dtFiles = sc.getChangedFiles("myproject/branches/5.1/");
etc.
私の顧客は、GitのかSourceGearのために求めて起動したときに今、私はちょうどそれらのクラスを作成し、非常に少ない他を変更する必要があります。
参照http://stackoverflow.com/questions/417590/abstract-classes-and-methods-in-java-inheritance and http://stackoverflow.com/questions/239127/exact-use-of-abstract-クラス – jason
と... http://stackoverflow.com/questions/56867/interface-vs-base-class – jason