Can you elaborate a bit on point 5: "You don't need to provide both the
provider interface...".
I'm wondering where the syntax changes would be.
Actually, after having a fourth look at the code, I realized something. This
was actually pseudo-code based on what I wrote this past Friday, and if I
recall correctly the client side call looked like so:
IUserProvider x = ProviderFactory<IUserProvider, User>.CreateProvider();
User y = x.Get(10);
And I believe CreateProvider() was roughly this:
class ProviderFactory<I, T> where I: IEntityProvider where T: BaseEntity
{
public static I CreateProvider()
{
if ( T.GetType() == typeof(User) )
UserProviderSql() up = new UserProviderSql();
return (I)up;
else throw new Exception("This is a test.");
}
}
So, I hardcoded an IEntityProvider implementation in there just for testing so
I could test the client side call, which worked. The actual code I wrote is
similar but uses an internal jump-table to call methods on various methods that
return concrete types based on the type of T where T is a BaseEntity. But I
think the cast of UserProviderSql to I is correct, and actually baffling why I
have to do that since UserProviderSql implements IUserProviderSql which extends
IEntityProvider<T> where T BaseEntity.
I guess it's a proof-of-concept, or just a day of research based on a comment I
saw in some pre-existing code about replacing cast-style calls from base
classes to generics.
Ron
-----Original Message-----
From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf
Of Marc Brooks
Sent: Sunday, July 01, 2007 8:50 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Looking for comments on the following code
A tiny bit better (warning, GMail syntax checked)
1) Base "should" be at the end if type names
2) Get implies single entity, Find implies collection
3) Make sure you have a base interface for Entities if you might need
polymorphic collections (like Managers and Employees in a single
query) that returns only the base class.
4) Return IList<T> not List<T> so you can swap the returned type easily.
5) You don't need to provide both the provider interface and entity
type, it can infer the provider type.
interface IEntityProviderBase
{
EntityBase Get(int id);
IList<EntityBase> FindAll();
}
interface IEntityProvider<T> : IEntityProviderBase
where T: BaseEntity
{
public new T Get(int id);
public new List<T> FindAll();
}
interface IUserProvider : IEntityProvider<User>
{
User FindByLastName(string lastName);
}
class ProviderFactory<T>
where T: EntityBase
{
public static IEntityProvider<T> CreateProvider(){}
}
IUserProvider x = ProviderFactory<IUserProvider>.CreateProvider();
User y = x.FindBy...
IList<User> yy = x.FindAll();
--
"It's not the quality of journalism that is sinking e-media companies, it
the quality." Thom Calandra - CBS Marketwatch
Marc C. Brooks
http://musingmarc.blogspot.com
===================================
This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com