接口到底能不能实例化?
来源:互联网 发布:考勤机表格修改数据 编辑:程序博客网 时间:2024/06/10 04:25
接口到底能不能实例话,在我以前看来是不行的,看了PetShop3后,感觉不是这样的。
数据访问层的DAL工厂:
namespace PetShop.DALFactory {
public class Account
{
public static PetShop.IDAL.IAccount Create()
{
/// Look up the DAL implementation we should be using
string path = System.Configuration.ConfigurationSettings.AppSettings["WebDAL"];
string className = path + ".Account";
// Using the evidence given in the config file load the appropriate assembly and class
return (PetShop.IDAL.IAccount) Assembly.Load(path).CreateInstance(className);
}
}
}
返回的是被转换为IAccount接口的实现了IAccount接口的对象,类似多态。我的理解是这样的:
比如某个类实现了该接口,如类Connection实现了该接口,则Connection类的
实例化对象可以给IConnection接口. 如 IConnection objIConnection = new Connection()
下面具体实现都基于接口进行操作。
在业务逻辑层,他是这么做的,符合上面的想法:
public class Account {
public AccountInfo SignIn(string userId, string password) {
// Validate input
if ((userId.Trim() == string.Empty) || (password.Trim() == string.Empty))
return null;
// Get an instance of the account DAL using the DALFactory
IAccount dal = PetShop.DALFactory.Account.Create();
// Try to sign in with the given credentials
AccountInfo account = dal.SignIn(userId, password);
// Return the account
return account;
}
......
- 接口到底能不能实例化?
- 接口到底能不能实例化。
- java接口中能申明私有成员么?接口能不能实例化?
- java接口中能申明私有成员么?接口能不能实例化?
- Win7到底能不能“裸奔”?
- 摆地摊到底能不能赚钱?
- 隔夜茶到底能不能喝?
- 分类到底能不能添加属性?
- MIP到底能不能提升排名
- 【UNITY多语言化问题】NGUI的多语言本地化Localization到底能不能使用
- lock free到底能不能提高性能
- 硬件防火墙到底能不能防DDOS?
- 开源到底在中国能不能发展?
- 屌丝到底能不能逆袭
- auto_ptr到底能不能作为容器的元素?
- U盘到底能不能直接拔下?
- 一棵树到底能不能结18种果子
- 分享:电脑虚拟内存到底能不能关掉
- 半年内的计划
- MySee创业团队:舍我其谁
- 2007-8-15
- 手机辐射
- 理解沃伦巴菲特
- 接口到底能不能实例化?
- 商店商品管理系统
- struts标签bean:cookie,bean:write,logic:page,logic:present,logic:iterate使用实例
- 垂直搜索:主题搜索理论(转)
- System.Net.Mail发送邮件失败所在
- 迪拜(三)不堪回首
- [vb.net]对TRY语句的感慨
- 带参数模版方法实现机制
- JavaScript学习笔记6--阻止向文本框输入指定的字符