现在有一个CLASS 名称是: modelDao ,它是我的系统中的底层抽象数据操作类.public void InsertObject(object obj){
//略
}public object GetObject(string title){
//根据title提取一个对象
}
为了方便起见,我把所有的对象类型都认为是object.看到泛方面的资料后,我有个想法,是不是能把 object 换成 "泛"如, public T GetObject(string title){
///
}
//略
}public object GetObject(string title){
//根据title提取一个对象
}
为了方便起见,我把所有的对象类型都认为是object.看到泛方面的资料后,我有个想法,是不是能把 object 换成 "泛"如, public T GetObject(string title){
///
}
///
}
public IList<object> GetList(string title){}是不是写成 这样呢!?
public T GetList<T>(string title){}这样返回来 T 我怎么确定它是 IList 呢!?
{}
using System;
using System.Collections.Generic;
using System.Text;namespace FinaHome.IDAL
{
public interface IGenericDao<T, U>
where T : class
where U : struct {
/** Persist the newInstance object into database */
U create(T newInstance); /** Retrieve an object that was previously persisted to the database using
* the indicated key as primary key
*/
T read(U key); /** Save changes made to a persistent object. */
void update(T transientObject); /** Remove an object from persistent storage in the database */
void delete(T persistentObject); }
}