This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Bean Inheritance Pattern  RSS feed

jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Going through some code at work, and I stumbled upon some bean inheritance I hadn't seen before.
Say you have a BaseHome, and you have two home interfaces that derive from it, like BaseHomeA and BaseHomeB. BaseHome's findByPrimaryKey returns a BaseBean, while BaseHomeA returns BaseBeanA and BaseHomeB returns BaseBeanB. The program's guts really only cares about dealing with BaseBeans, so eventually we want to get to that generic interface.
The way the previous coders went about doing it was with reflection, like the following:

I'm not sure if the use of reflection here is costly in resources, but is this typical? We're using the 2.0 spec, so I'm curious if we need to be going the long away about it anymore, or if the new inheritance capabilities that were introduced will allow something simpler, like:
BaseHome bh = (BaseHome)jndiLookup( name );
BaseBean bb = bh.findByPrimaryKey( key );
Just looking for some feedback that might help us tidy things up, unless this way of doing things is already as simple as we can get
[ June 24, 2003: Message edited by: jason adam ]
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!