Last time I blogged I mentioned the SDGN as a Dutch .net developpers association. Jonne Kats pointed out I did not mention DotNed. An organization I do not know personally but they have a good meeting planned for the 26th.
Lately I've been strugling somewhat with constructors. Every class does need a default (that is parameterless) constructor to be a base class. Take this class decalaration
public class DLitem
{
private DataListItem dlItem;
public DataListItem Item
{ // do something }
public DLitem(DataListItem item)
{
dlItem = item;
}
}
This class has only one, overloaded, constructor. It compiles fine but the moment you try to create a derived class the derived class won't compile until you add a default constructor to the base class
public class DLitem
{
private DataListItem dlItem;
public DataListItem Item
{ // do something }
public DLitem()
{
}
public DLitem(DataListItem item)
{
dlItem = item;
}
}
Now your descendent classes will compile.
private class ListTemplate : Algemeen.DLitem
{
// New members here
}
To use the overloaded constructor of the base class you have to overide it, even if the override does not add any functionality
public ListTemplate(System.Web.UI.WebControls.DataListItem item) : base(item)
{
}
No extra implementation needed so : base(item) will do to call the constructor of the base class.
I had read the advise : "allways give your class a default constructor", and now I've seen the compiler enforces it.. But I am still somewhat puzzeled by the fact I have to override the overload constructor. Back to the library.
Blog On.
Peter