Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does implementing Interface both implicit and explicit make sense?

I'm currently studying for my MS 70-515 exam. In one of the practices the author implements an interface both implicit as well as explicit. The explicit implementation just calls the implicit implementation. The explicit implementation is just listed without an explanation.

Does it make sense to have both an implicit and an explicit implementation of the interface? I would think the explicit implementation is redundant (in this case).

public class PassTextBox : TextBox, IScriptControl
{
    public virtual IEnumerable<ScriptDescriptor> GetScriptDescriptors()
    {
        var descriptor = new ScriptControlDescriptor(
            "AjaxEnabled.PassTextBox", ClientID);
        // ...
        return new ScriptDescriptor[] {descriptor};
    }

    IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
    {
        return GetScriptDescriptors();
    }
}

BTW, the code seems to run just fine without the explicit implementation, as the implicit implementation is public.

It concerns MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4 Chapter 9, Lesson 2, Practice 3 to be precise.

like image 617
comecme Avatar asked Apr 15 '12 19:04

comecme


1 Answers

The explicit implementation seems to be totally superfluous.

I can't think of a way to call it where it would make a difference if you left it out.

There is one small difference, the implicit version is virtual meaning it could be overridden. The explicit version will always be called at this entry point. But since it only calls the virtual member that difference is not used here.

like image 94
Henk Holterman Avatar answered Sep 29 '22 23:09

Henk Holterman