Newbie Qn - Interfaces as parameters and members
- From: "steve" <steve@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 10 Aug 2005 19:55:05 -0700
Hi all
I want to know if I can have interfaces as formal parameters in methods.
For instance, if I have something like this
public interface INameTranslator
{
string sToLocal(string sRemoteName);
string sToRemote(string sLocalName);
}
Can I do this..
public class CMyNameTranslator: INameTranslator
{
public string sToLocal(string sRemoteName)
{
return sRemoteName;
}
public string sToRemote(string sLocalName)
{
return sLocalName;
}
}
public class CFoo
{
public INameTranslator mNameTranslator;
CFoo(INameTranslator NameTranslator) //<<--- Is this legal /desirable
{
mNameTranslator = NameTranslator;
}
}
AND then somewhere else..
CMyNameTranslator NameTranslator = new CMyNameTranslator();
CFoo Foo = new CFoo(NameTranslator);
string sTemp = Foo.mNameTranslator.sToLocal("Bob"); // sTemp should be
"Bob"
Cheers
Steve
.
- Follow-Ups:
- RE: Newbie Qn - Interfaces as parameters and members
- From: Mark R. Dawson
- RE: Newbie Qn - Interfaces as parameters and members
- From: Mark R. Dawson
- RE: Newbie Qn - Interfaces as parameters and members
- Prev by Date: Re: Start Process with different user
- Next by Date: RE: Inheritance and interface implementation.
- Previous by thread: Inheritance and interface implementation.
- Next by thread: RE: Newbie Qn - Interfaces as parameters and members
- Index(es):