I am working on a class which needs to be run on a different process based on the type of object I need what I pass. I thought overloading could work here, but I have a question. Say I have two interfaces:
Public interface IEmail {some properties ...} and
Public Interface ISEELEmail: IEEML {some more property ....} and a class to process on these objects:
public class email processor {Public Zero Process E-mail (IEML Email) {Accessories; } Public Zero ProcessEmail (IspecialEmail Email) {different stuff}} My question is is that ISpecialEmail got from IEML, is the signatures of these systems sufficiently different to overload ? My basic idea is that the ISEELmail emails will also trigger the IEML signature, because this interface also applies to technically as well.
Thank you for your help.
It depends on how you call methods
For example, suppose you have email: email and special email: ispecialEmail . If you have declared a list of emails: list & lt; IEmail & gt; Email = New List & lt; IEmail & gt; {New email (), new special email ()}; and then ran
foreach (different emails in email) {EmailProcessor.ProcessEmail (email)} This will call for the public zero process email - because the call binding happens at compile time (i.e. it does not work as you wish Will). If you do something similar, it will also fail:
var email = GetEmail (); // either IEmail or IExtendedEmail EmailProcessor.ProcessEmail (email); // will only call the Process E-mail (IEMEM) So, the polymorphism with those signatures will fail.
However, the following will work:
var email = GetEmail (); // returns only IEmail var enhanced email = GetExtendedEmail (); // only IExtendedEmail EmailProcessor.ProcessEmail (email); // All Process Email (IEEME) Email Processors Processmail (extended email); // Process is called e-mail (IExtendedEmail)
No comments:
Post a Comment