My impression and the way I make use of interfaces, base classes, and
classes is this:
Interfaces define the contract of an objects structure
in C# interface <interface name here{}
in VB Interface <interface name here>
End Interface
Base classes define a contract for derived class yes, but also maintain
functional control as well.
in C# abstract class <class name here>{}
in VB Mustinherit Class <class name here>
End Class
Classes then implement their base class and interfaces to fulfill any
contracts, and provide any customizations to the overriable members of the
base class, extend the base class, and implement interface members.
Take a look at the sample below, the sample was for another post, but the
ideas are still teh same.
internal interface IBaseElement
{
void Execute();
}
internal abstract class baseclass<Twher e T : IBaseElement
{
protected List<TmSelected ;
protected baseclass()
{
mSelected = new List<T>();
}
protected abstract Type GetElementType( );
protected abstract void ReportProgress( decimal percentComplete , int
position);
protected abstract void UpdateControls( );
protected void DoSomething()
{
for (int i = 0; i < mSelected.Count ; i++)
{
IBaseElement tempElement = (IBaseElement)m Selected[i];
tempElement.Exe cute();
ReportProgress( i / mSelected.Count , i);
if (mSelected.Coun t 1)
{
UpdateControls( );
}
}
}
}
internal class DistributionRow Status : IBaseElement
{
#region IBaseElement Members
public void Execute()
{
//
}
#endregion
}
internal class ReportRowStatus : IBaseElement
{
#region IBaseElement Members
public void Execute()
{
//
}
#endregion
}
internal class Class1 : baseclass<Distr ibutionRowStatu s>
{
public Class1():base()
{
//
}
protected override Type GetElementType( )
{
return System.Type.Get Type("Distribut ionRowStatus");
}
protected override void ReportProgress( decimal percentComplete , int
position)
{
//Do custom work here
}
protected override void UpdateControls( )
{
//Do custom work here
}
}
internal class Class2 : baseclass<Repor tRowStatus>
{
public Class2(): base()
{
//
}
protected override Type GetElementType( )
{
return System.Type.Get Type("ReportRow Status");
}
protected override void ReportProgress( decimal percentComplete , int
position)
{
//Do custom work here
}
protected override void UpdateControls( )
{
//Do custom work here
}
}
"Rich" <Ri**@discussio ns.microsoft.co mwrote in message
news:E9******** *************** ***********@mic rosoft.com...
Greetings,
I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I
just want to ask about the relationship between Abstract Classes and
Interfaces.
My first question is if C# even has Iinterfaces. I took some Java
programming classes and Interfaces are a main staple of Java. And in
VB.Net
I use interfaces for setting up definitions of classes. I am guessing
that
Abstract classes in C# do the same thing as Interfaces in VB.Net - define
class structures.
Am I correct in my thinking about Abstract classes in C#? Does C# have
Interfaces? If so, then a C# Interface would be different than a VB.Net
interface. If not, then I can think that Abstract Classes of C# function
the
same as Interfaces in VB.Net.
Any enlightenment/clarification greatly appreciated.
Thanks,
Rich