I will give an example of the real world. I have an abstract call to the cSourceControl class. Then I have a class for Visual Source Safe call cVSS and one for Subversion cSVN, both inherited from cSourceControl.
Now an abstract class has properties and methods of binding (yes, with code) that only inheriting classes can use. An abstract class also defines a bunch of abstract methods that an inherited class must implement:
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);
From this, you can say that each of them will be needed by the SourceControl class, but the way it looks in cVSS is very different from how it looks in cSVN. Another benefit is that at runtime I can choose VSS or SVN. A simplified snapshot of the code could be:
cSourceControl sc; if(usingVSS) sc = new cVSS(); else sc = new cSVN(); DataTable dtFiles = sc.getChangedFiles("myproject/branches/5.1/"); etc.
Now that my clients start asking for Git or SourceGear, I just need to create these classes and modify them a bit.
Jbrooks
source share