my dog learned polymorphism*
The moose likes Performance and the fly likes Good Code? Bad Code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Good Code? Bad Code?" Watch "Good Code? Bad Code?" New topic
Author

Good Code? Bad Code?

YuenLian Wu
Ranch Hand

Joined: Nov 16, 2005
Posts: 73
Hi all,

I have a Performance question want to ask. The original code are shown in the below:



quote:
--------------------------------------------------------------------------------


public static String[] itemDetails =
{ "item ID", "item Title", "item Description", "item Price", "quantity in stock", "quantity in order", "release day"};

public static String[] cdDetails =
{ "CD type", "artist name", "number of Tracks", "Duration" };

public static String[] bookDetails =
{ "Book type", "ISBN", "author name", "publisher" };


public List addItem() {

boolean isCD = true;
List list = new List();
BookStoreUtility bsUtil = new BookStoreUtility();

CD cd = new CD();
Book book = new Book();

for ( int i = 0; i < itemDetails.length; i++ ) {

input = Keyboard.readStr(); // get input from users

if ( i == 0 ) {
if ( ( input.charAt(0) == 'c' || input.charAt(0) == 'C') )
isCD = true;
else
isCD = false;
}

if (isCD)
PopulateCD(i, input, cd);
else
PopulateBook(i, input, book);
}

list.add(cd);

return list;

}

--------------------------------------------------------------------------------



I have a addItem method that get inputs from user. I have 3 classes(Object), they are Book, CD and Item. Book and CD objects are extending from the Item object. At first, the DataEntry Person would need to input the ItemID. If the ItemID is started with "C", that means he/she is inserting CD's information, and all the inputs will be populated to CD object, and it works the same way for Book Object, ...etc. All the input parameters names will be stored in a String[], such as itemDetails, cdDetails, etc.

However, the program doesn't know the User is inserting whether the Book or CD information at the beginning, so by default i will just use a forLoop to read all the parameters from String[] itemDetails. After the user entered the first parameter, the program knows the user is inserting wheter CD or Book. I would like to concat the cdDetails or bookDetails String array to the default itemDetails String array so that all the required parameters can be read from user.

I would like to get some nice suggestions on how to implement this thing. I want to learn how to design fast, dynamic and portable codes. Please help me out.

Thanks in advance

Transistor
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
This isn't a performance question. I posted an answer here though:

http://www.coderanch.com/forums/


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Good Code? Bad Code?
 
Similar Threads
Storing of Data
Performance of Java Object Referece
Error with Arraylist object returning from SessionBean
Unable to import javabean class in servlet
printing message