适配器类和目标类都实现相同的接口......为什么我不能像对待同一个对象那样对待它们?发生为什么我在这里遇到转换错误?
interface ISmartPhone
{
string Name { get; set; }
string Type { get; set; }
void ShowTextWithImage();
}
public class BasicFlipPhoneAdapter : ISmartPhone
{
IBasicPhone basicPhone;
public BasicFlipPhoneAdapter(IBasicPhone basicPhone)
{
this.basicPhone = basicPhone;
}
public string Name { get; set; }
public string Type { get; set; }
public void ShowTextWithImage()
{
basicPhone.ShowBasicText();
}
}
public class iPhone : ISmartPhone
{
public string Name { get; set; }
public string Type { get; set; }
public void ShowTextWithImage()
{
Console.WriteLine("O.o cool image!");
}
}
错误:
iPhone flipPhoneAdapter = new BasicFlipPhoneAdapter(flipPhone);
界面是什么样的? – doctorless