How can I set properties of the concrete class while programming against interfaces?

J

Julia

Hi,

In general my question is how can I set properties on a concrete class
while programming against interfaces


For example I have a MailServerFatory which can create two types of
Mail servers and return IMailServer


public interface IMailServer
{
void Send();
MailServerType Type {get;}
}


the first is SMTP server

public class SMTPMailServer : IMailServer
{
public void Send(){}
public string SMTPHost
public MailServerType Type

}

The second is EXCHMailServer

public class EXCHMailServer:IMailServer
{

public string UserName
public string PassWord
public string Folder
public void Send()
public MailServerType Type
}


When one of the properties of the current mail server changed i would like
that the application will set it.
I know of course that I can add
OnPropertyChanged(PropertyName,PropertyValue) to the IMailServer
but I am looking for other way.

I was thinking about reflection,but can I get the concrete class from an
interface?

Thanks in advance
 
G

Guest

If I understand you correctly, the best way to do it is just to make the
property at the interface as set as well as get:

For example:

MailServerType Type {get; get}

And now the user of the interface can change the property value of the
concrete class.

Hope it helps
Sharon G.
http://sharong.agreatserver.com/
 
G

Guest

You have two choices:
1. To add each property you realize to the interface class with set and get.
2. Or instead of using a Interface class, use abstract class that include
all the properties you realize and give them some default implementation that
the derived classes can override.

I don’t know what else can be done.


Hope it helps
Sharon G.
http://sharong.agreatserver.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top