Finally, discussing with you a technical issue due to introducing DEF.
Old rules, still first see a code:
Code 6: DEF polymorphism in Interface inheritance
Public Abstract Class Defbase: IList, iDictionary
{
// is both an interface method and is declared as Virtual
Public Virtual IEnumerator getENUMERATOR ()
{
IF (_al! = null)
Return_al.geetenumerator ();
Else IF (_ht! = null)
Return_ht.getenumerator ();
Else
{
// Throwing the base class unable to handle exception
Throw new Exception
"Do Not Handle Interface Method in Defbase Class!");
}
}
}
Public Class MyDef: Defbase, IList, IenuMerable
{
// is both an interface method and is declared as Override
Public override ienumerator getenumerator ()
{
Try
{
// First call the DEFBASE's interface method,
// If the base class cannot be processed, the abnormality throwing it is
Return Base.GeteNumerator ();
}
Catch
{
IF (this._ostorm! = NULL)
Return getList (). getenumerator ();
Else IF (this._xmlnode! = null)
Return_Xmlnode.GeteNumerator ();
Else IF (this._xmldoc! = null)
Return_Xmldoc.GeteNumerator ();
Else
Throw new Exception
"Do Not Handle Interface Method In MyDef Class!");
}
}
}
}
I don't know if the comment section has been clear: When inheriting from the Interface, because there is still a base class (defbase) such a fact, MyDef has to expand this Interface implementation!
At the same time, because the MyDef instance also exists in the case of "using defbase interface implementation" (for example: Entity Type is arraylist or hashtable), prompting us to use some very means to adjust!
Here, the author uses an exception handling method (a little cleaned taste), once the base class DEFBase is unable to process, directly throw Exception (if full point, you need to define the Exception Type in advance to filter processing), so layer layer Upward, if finally the class of catch, it is still unable to handle, it is really a system unusual!
There is also a way to be a slightly complex point: NULL can be returned in Defbase and judge in MyDef, but for Interface Method without returning any value or returning value for valueetype, you must have another way (for example, a Null Type Class) Treatment, similar to the system.dbnull in .NET Framework! Next paragraph: http://www.9cbs.net/develop/read_article.asp? Id = 27550