Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / August 2007

Tip: Looking for answers? Try searching our database.

Enums or Key/Value Pairs?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HenryCC - 03 Aug 2007 22:18 GMT
We are trying to develop a set of C# 2.0 web services that are data driven,
loosely coupled, easy to maintain, and somewhat high preferment (I'm sure
that's either an oxymoron or everyone else's dream too?!?) Anyway, we need to
be able to take an "arbitrary" number of key (or name) /value pairs that do
have a finite, but changeable, set of possible values to them. What is the
best (practice) approach to accomplishing this without compromising (too
badly) any 1 of the 4 qualities that we are looking for?

For example, let’s say we have a webmethod called "RegisterVehicle" that
takes a "Vehicle" as the input. The Vehicle can be of type "Car", "Truck", or
"Motorcycle". If it's a "Car", then we would need to know "How many doors",
"Make", "Model", "How many cylinders the engine has", and the "Type of fuel".
For a "Truck" we would have the same, but maybe add "4 Wheel Drive or not"
and "Bed length". For "Motorcycle" we wouldn't need "Number of doors". And so
on and so forth.

So as you can see, some of the inputs are somewhat set (Car, Truck, or
Motorcycle), but the others could change at any time and are mostly dependant
on the type of Vehicle that you are submitting.

If we create enums and expose those through the WSDL, we would need to
recompile and redeploy our services, plus existing client may need to do the
same. However the validation is "free", but we would probably also have to
maintain enums in C# code as well as "enums" in the database.

If we take an "array" of key/value pairs with some min/max bounding
constraint, it make the validation of those key/value pairs a bit more error
prone (i.e. just doing string comparisons, room for type-o's, etc.), but is
much more flexible in what can be passed in by any given client application.

Anyone dealing with this type of thing now?
Spam Catcher - 04 Aug 2007 18:47 GMT
> If we take an "array" of key/value pairs with some min/max bounding
> constraint, it make the validation of those key/value pairs a bit more
> error prone (i.e. just doing string comparisons, room for type-o's,
> etc.), but is much more flexible in what can be passed in by any given
> client application.

How about a numeric code instead? 1 for car, 2 for truck, etc.

Numeric codes are harder to remember, but less prone to typos. As long as
you provide sufficient documentation, the developer should have no problem
figuring out which code to use.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.