473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Generics vs. polymorphismsm

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

Aug 17 '06 #1
2 1091
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)

"ma**********@gmail.com" wrote:
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

Aug 17 '06 #2
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 <Tin the cast...

Mark

David Jessee wrote:
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)

"ma**********@gmail.com" wrote:
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
Aug 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Bernardo Heynemann | last post by:
How can I use Generics? How can I use C# 2.0? I already have VS.NET 2003 Enterprise Edition and still can´t use generics... I´m trying to make a generic collection myCollection<vartype> and...
2
by: Mr.Tickle | last post by:
So whats the deal here regarding Generics in the 2004 release and templates currently in C++?
23
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
5
by: anders.forsgren | last post by:
This is a common problem with generics, but I hope someone has found the best way of solving it. I have these classes: "Fruit" which is a baseclass, and "Apple" which is derived. Further I have...
9
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal...
1
by: Vladimir Shiryaev | last post by:
Hello! Exception handling in generics seems to be a bit inconsistent to me. Imagine, I have "MyOwnException" class derived from "ApplicationException". I also have two classes...
7
by: SpotNet | last post by:
Hello NewsGroup, Reading up on Generics in the .NET Framework 2.0 using C# 2005 (SP1), I have a question on the application of Generics. Knowingly, Generic classes are contained in the...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.