javasystem-designdomain-model

Enterprise java app architecture. Dynamic domain model


I wonder what is the best way to implement dynamic domain model persisted in SQL database? Saying dynamic domain model I mean such model when user can change "class" of object by adding or removing properties.

For example: little internet shop where manager can add new types of product with web-interface. Should I use something like Map everywhere? Maybe it is better to keep only dynamic part of object in Map? Or maybe runtime class generation will help? Or I should take a tour over dynamic languages like Groovy? I have tested first and second methods and this is real headache to develop in such way.

What is the common practise?


Solution

  • You have a 1 to 1 from product to product type. So product has a member var called productType. You'll also have a 1-to-many from product to features. So the product class will have a list of features.

    I can't imagine a more wrong way to do this then using cglib to create classes on the fly.