| Below is the sample working code + driver in case anyone else runs
| across a similar issue.
Iµ'm sorry, but I really have to ask why on earth you are doing the extra
step of inheriting from a generic class just to get classes that are
differently named ??
| // Data Access Object for a Person model.
| class PersonDao : Dao<Person>
[quoted text clipped - 4 lines]
| }
| }
This is totally unnecessary. What is wrong with just using Dao<Person > or
Dao<Thing> ?
Then you don't even need your factory :
public class Dao<modelT>
{
private modelT model;
public Dao(modelT model)
{
this.model = model;
}
public modelT Model
{
get { return model; }
}
}
{
Person p = new Person();
Dao dao = new Dao<Person>(p);
Model model = dao.Get();
// or you could assign it straight itno a Person, if you could be sure of
the type...
if (dao is Dao<Person>)
Person person = (Person) dao.Model
...
}
Or am I missing something ?
Joanna

Signature
Joanna Carter [TeamB]
Consultant Software Engineer
David Browne - 14 Aug 2006 04:29 GMT
> | Below is the sample working code + driver in case anyone else runs
> | across a similar issue.
[quoted text clipped - 14 lines]
> This is totally unnecessary. What is wrong with just using Dao<Person > or
> Dao<Thing> ?
Presumably because PersonDao has additional implementation logic particular
to Person. Typically this would be somethind like key access or lookup
methods. EG:
public Person Lookup(string FirstName, string LastName)
This obviously can't go in the definition of Dao<TModel> since it applies
only for a particular TModel type.
David
Bryan Kyle - 14 Aug 2006 19:42 GMT
> | Below is the sample working code + driver in case anyone else runs
> | across a similar issue.
>
> Iµ'm sorry, but I really have to ask why on earth you are doing the extra
> step of inheriting from a generic class just to get classes that are
> differently named ??
The reason I'm wanting to use generics for this is so that I can define
a parameterized interface for the ModelDAO objects. For example, each
ModelDAO needs to have a Get method that is passed a type of Model and
will return an instance of the same type.
e.g.
public class PersonDAO
{
public Person Get(Person person);
}
public class ThingDAO
{
public Thing Get(Thing thing);
}
Had I not used generics for this, then implementing these methods would
be either left up to a development policy, or written generically:
public class PersonDAO
{
public Model Get(Model model);
}
While there's nothing wrong with that approach, it doesn't seem as
clean and again it is left up to the developer and the runtime
environment to determine if a given Model can be persisted using a
given ModelDAO.
> | // Data Access Object for a Person model.
> | class PersonDao : Dao<Person>
[quoted text clipped - 44 lines]
>
> Joanna