Generics rock and I believe they shine in more places than just in collections. I was a little disappointed to see that you dropped generics all together! [;)]
In addition, do you know about the new TableAdapters in 2.0....HOLY YES! They rock as well. Anyway, I wanted to throw my two cents out there. This is one way you could implement your BOM:
public class HighSchool {
int iD;
string principle;
string name;
public int ID {
get { return this.iD; }
set { this.iD = value; }
}
public string Principle {
get { return this.principle; }
set { this.principle = value; }
}
public string Name {
get { return this.name; }
set { this.name = value; }
}
}
public interface IDataAccessLayer<T, K> {
T Get(K primaryKey);
void Save(T item);
void Delete(T item);
}
public abstract class DataLayerBase {
private string connectionString;
public DataLayerBase(string connectionString) {
this.connectionString = connectionString;
}
public class HighSchoolDataLayer : DataLayerBase, IDataAccessLayer<HighSchool, int> {
public HighSchoolDataLayer(string connectionString) : base(connectionString) { }
public HighSchool Get(int primaryKey) {
throw new NotImplementedException();
}
public void Save(HighSchool item) {
throw new NotImplementedException();
}
public void Delete(HighSchool item) {
throw new NotImplementedException();
}
}
In addition, you will notice that I was able to implement the interface implicitly which does not require the additional interface methods implementaion.
Member
660 Points
494 Posts
Re: Converting to Generics
Oct 15, 2005 01:53 AM|nicequy|LINK
Generics rock and I believe they shine in more places than just in collections. I was a little disappointed to see that you dropped generics all together! [;)]
In addition, do you know about the new TableAdapters in 2.0....HOLY YES! They rock as well. Anyway, I wanted to throw my two cents out there. This is one way you could implement your BOM:
public class HighSchool {
int iD;
string principle;
string name;
public int ID {
get { return this.iD; }
set { this.iD = value; }
}
public string Principle {
get { return this.principle; }
set { this.principle = value; }
}
public string Name {
get { return this.name; }
set { this.name = value; }
}
}
public interface IDataAccessLayer<T, K> {
T Get(K primaryKey);
void Save(T item);
void Delete(T item);
}
public abstract class DataLayerBase {
private string connectionString;
public DataLayerBase(string connectionString) {
this.connectionString = connectionString;
}
protected string ConnectionString {
get { return this.connectionString; }
}
}
public class HighSchoolDataLayer : DataLayerBase, IDataAccessLayer<HighSchool, int> {
public HighSchoolDataLayer(string connectionString) : base(connectionString) { }
public HighSchool Get(int primaryKey) {
throw new NotImplementedException();
}
public void Save(HighSchool item) {
throw new NotImplementedException();
}
public void Delete(HighSchool item) {
throw new NotImplementedException();
}
}
In addition, you will notice that I was able to implement the interface implicitly which does not require the additional interface methods implementaion.
Hope this helps,
Jason