Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Bean Design : Best Practice  RSS feed

amit bose
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a database table T1(with 20 fields) and based on them I need to generate some XML files, say F1,F2,F3
I have methods: generateXMLFile1(x), generateXMLFile2(y), generateXMLFile3(z) which would create F1,F2,F3
Also, F1 uses 10 fields from T1, F2 uses 5 and F3 uses 15 fields.

Soln1: Create a bean class 'commonB' based on 20 fields of T1 and depending on XML file being generated,
populate fields and pass 'commonB'.
i.e. in case of generating F2 file, just populate commonB with 5 fields and call generateXMLFile1(commonB objCommonB)

Soln2: Create three bean classes B1(for F1 with 10 fields),B2(for F2 with 5 fields),B3(for F3 with 15 fields)
and invoke generateXMLFile1(B1 objB1) for F1 and so on for others.

(Please note that by bean,I mean simple Java bean and not EJBs)

Downside of solution1 is that e.g. in F2 generation we are using only 5 bean fields out of the 20 available fields
I am not sure if this causes performance issues.

Downside of solution2 would be we are creating a number of Java classes.i.e.down the line if we need to create
10 more XML messages, then 10 additional bean classes would be required.

Where should the tradeoff be done so that a optimal design is obtained?
Which approach id more performant?

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!