I have the following class:
public abstract class TableServiceEntity
{
protected TableServiceEntity();
protected TableServiceEntity(string partitionKey, string rowKey);
.....
.....
}
I inherit from this class as follows:
public class AuditableTableServiceEntity : TableServiceEntity
{
public string CreatedBy { get; set; }
.....
.....
}
I use the class as follows:
public class Note : AuditableTableServiceEntity
{
public Note() { }
public Note(string dsValue, string pk)
: base(pk, Seq.GetNext(dsValue, pk, "Note").ToString("00000")) { }
It fails saying that the class AuditableTableServiceEntity does not have a constructor that takes two arguments. To fix I tried to add the following methods to AuditableTableServiceEntity. Is this a valid thing to do or is there some other way? Also I notice it requires me to add a constructor that takes zero arguments. Why is that?
public AuditableTableServiceEntity()
: base()
{
}
public AuditableTableServiceEntity(string pk, string rk)
: base(pk, rk)
{
}
Can someone give me advice as to if I'm on the right track or if there is some better way of doing this. Should I declare the methods on AuditableTableServiceEntity as protected and also should I declare that class as abstract?
Can someone give me advice as to if I'm on the right track or if there is some better way of doing this.
This is the correct approach.
Should I declare the methods on AuditableTableServiceEntity as protected and also should I declare that class as abstract?
It depends. Should the user be able to directly construct an instance of an AuditableTableServiceEntity? If so, then the constructors should be public, and the class should not be abstract.
If, however, it doesn't make sense, and the user should always construct a Note or other similar class, then protected constructors and an abstract class is appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With