-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Best way to map the strategy pattern
PostPosted: Wed Nov 23, 2005 10:42 am 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
Hi, I was wondering what is the best practice you have found to map a strategy. Suppose you have an object Foo that can have a relationships to a stretegy from a family.

One way would be to map to in a private field the Stretegy class name and instantiate it in runtime using reflection. Another would be to use a new table with table per hierarchy. This table seems a bit awkward since it will only have an ID and a class discriminator. Finally I guess there must be other options that I haven't considered yet.

Any thoughts??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 12:50 am 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
Another possibility is to create a user type which knows how to map an integer column to strategy instances. The problem with this approach is that the mapping is hard coded in the user type.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 9:40 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Or map a class name to a strategy instance, that way you won't have to hard code anything.

Actually, even if you go with table-per-hierarchy, I think you may need to store strategy "configuration options" later on, and the table might become a good place for those.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 12:41 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
All of our entities have an associated strategy object, since our entity classes themselves contain only generated code.

We have an entity factory that keeps a dictionary of entity and strategy types to instantiate, given the class name only (replacements must preserve the class name -- i.e. the namespace and assembly must be different). Actually, for each type (entity or strategy), a stack of overriding types is kept, with each override in a given stack associated with a "customization layer". This allows customization layers to be enabled, disabled, added, etc. For entity types, the "top" override on its stack must be kept in sync with the assembly-qualified entity type name defined in the NHibernate mappings (*.hbm.xml files). Our entity generator / customization layer management utility assures this.

Our entity factory and our NHibernate interceptor then simply instantiate and attach the "top override" strategy class to all entity instances they provide.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.