Generics vs. polymorphismsm

M

mark.norgate

Not a problem really, just curious about other people's views...

I have written a control in ASP.NET 2.0 (derived from UserControl) for
a timesheet application that represents the entries for time charged to
a particular project for each day in the week. Now I must write two
very similar controls that represent potential projects and overheads.

There are only slight differences in appearance and function between
these two new controls I must write and the existing project control:
they use a different DataView, some of the drop downs have different
DataValueField values, and so on.

I'm wondering how best to accomplish this. Should I create a base
class, perhaps abstract, and support the various differences in
functionality using polymorphism? Or should I use generics (which I
like :) ) and instantiate the controls with a "service provider" class
as the type parameter that provides these services, which is tantamount
to the same thing since presumably the three service providers must be
derived from a common base class (or interface) so the controls can get
along with them.

I did read something about templated controls somewhere, but it wasn't
very well written so I abandoned the idea of trying to understand it.
Although perhaps that's what I need...

I imagine it's a case of six of one and half-a-dozen of the other,
although I'm more attracted to the latter alternative since it is
exploiting perhaps a more robust feature of the Framework and is
essentially a sort of Abstract Factory pattern implementation.

Any thoughts?

Mark
 
G

Guest

This is an opinion here....

Option 2.
plus....
Create internal or public properties in your user control that indicate the
service providers etc (you could actually have the service provider instance
be one of your peropties, or use a string) and allow the hosting page to set
those properties at runtime.
Granted, I'm not inside the wiring to see if that's going to be feasable,
but it does give you an extensible bit of functionality that can be leveraged
over and over again....(gotta love oop)
 
M

mark.norgate

Thanks for that. The (very) few people I've spoken to about the idea
have suggested the same thing.

Although, having said that, I am creating the control like this:

c =
(ProjectDetailsControl)LoadControl("~/Controls/projectDetails.ascx");

....so I'm expecting the compiler to throw a right wobbler if I include
a <T> in the cast...

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

generics puzzle 57
Generics Amanuensis? 2
[C#] Extend main interface on child level 0
Hairy generics question 29
Generics and user controls 8
Generics vs Individual classes 4
Generics 24
can this be done with generics? 32

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top