I’ve written one abstract class in my project. Then I realized that I have to understand clearly why we needed to use abstract class. As all we know that abstract class can not instantiate.
But we can use like standardize to inherit from all of sub-classes. My sample abstract class as follows. There is no implementation inside all of the abstract method and abstract properties, only will contain definition.
Abstract Class Sample :
All of the sub classes will override by inherit abstract class in order to implement actual logic of the methods and properties. Are you confuse now ? Please take a look at the following sample.
public abstract class AbstractClassSample
{
#region ” Abstract Properties ”
public abstract string FieldName1
{
get;
set;
}
public abstract string FieldName2
{
get;
set;
}
public abstract List<OtherObject> OtherObject
{
get;
set;
}
public abstract string TableName1
{
get;
set;
}
public abstract string TableName2
{
get;
set;
}
public virtual string Database1
{
get;
set;
}
public virtual string Database2
{
get;
set;
}
#endregion
}
When we call abstract class for subclasses, all the abstract method would be same and needed to contain in subclasses. So, Some property will same and some property will not same between abstract class and sub class, you can use virtual property in abstract class. Take a look at the following as sample.
public class diningOverviewObject : pagedataAbstract
{
private string _fieldName1 = string.Empty;
private string _fieldName2 = string.Empty;
private List<OtherObject> _bannerGroupObject = new List<OtherObject>();
private string _tableName1 = string.Empty;
private string _tableName2 = string.Empty;
#region Properties
public override string FieldName1
{
get{return _fieldName1;}
set{_fieldName1 = value;}
}
public override string FieldName2
{
get{return _fieldName1;}
set{_fieldName1 = value;}
}
public override List<OtherObject> OtherObject
{
get{return _fieldName1;}
set{_fieldName1 = value;}
}
public override string TableName1
{
get{return _fieldName1;}
set{_fieldName1 = value;} }
public override string TableName2
{
get{return _fieldName1;}
set{_fieldName1 = value;} }
#endregion
}








