Dynamic Forms -- OO Design dilemma

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good Morning All,

What we have is a dynamic business object that has varying numbers and types
of properties. What it models is a generic saleable product. Not all
products have the same properties. For instance, if you were selling
software you wouldn't have a color, if you were selling vases you wouldn't
have a file size. So, even though they are all generic products, they have
specialized properties. I know you're thinking "inheritance". But, we're
making something that needs to accomodate any number of possible product
types but not require a recompile. One solution needs to work for everyone.
Additionally, the form on which a user inputs these products needs to build
itself based on the properties of the product that they are inputting. So,
if they're inputting a furniture product, the form should prompt them to
enter height, width, weight, color, etc. Or, if they are inputting a car
product, the form should prompt them to enter properties specific to a car.
Of course, the admins of this system would be responsible for specifying
ahead of time what properties a given product must have.

So, the question is: How do you make a database driven varying property
object and also handle being able to generate a product input form, display
page, and data storage/retrieval of such?


Thanks in advance,
Nathan
 
I understand that much, and we have a similar architecture implemented. The
question is how do I now build the user interface (form) (in this case using
ASP.NET) based on all of the additional properties. I know I can add
dropdowns and textboxes dynamically, but how do I map these added controls to
the values of the Product object? And how to do it w/o mixing my user
interface, business logic, and database layer together (need loose coupling).
 
First, a disclaimer, I did not follow the link that Greg Young provided.

But as far as dynamic linking, it can be done. I have a WinForm that
provides a generic lookup for searching for anything in the database.
It uses generics, so if you wanted to prompt the user for a city, you
could use SearchBox<City> sb = new SearchBox<City();

The SearchBox<> uses attrbutes on the City class to determine which
fields / properties are searchable (so, reflection) and then builds text
boxes and databinds them to an instance of City.

It sounds maybe more complicated than it really is.

The basic is this, use Activator to get an instance of the class. Use
reflection to determine which fields to display, and then use
databinding to bind the instance to the controls.

--Brian
 
Hi,


You can use reflection, I did something like this when I was learning .net ,
you generate the page based on the properties of the type. using Labels for
RO properties and asp.net controls for the Set properties. I remember I used
attributes to give a description to the property , like "Enter Phone
number" for a PhoneNumber property for example.
The tricky part was detecting when a property was of a enum type and using a
dropdown accordingly.
 
It depends on how exactly you implemented your lower layers .. did you use
typed objects or did you use a property bag to return your data? I can tell
you now that if you use a property bag, the suggestions of going through
reflections will be one step above useless for you. How did you implement
type metadata for your user added columns (i.e. typing). Do you want
additional behaviors able to be added to the front end (such as supporting a
phone number on text box?)

Cheers,

Greg Young
MVP - C#
http://geekswithblogs.net/gyoung
 
Back
Top