aspose file tools*
The moose likes Servlets and the fly likes code reusability ideas? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "code reusability ideas?" Watch "code reusability ideas?" New topic
Author

code reusability ideas?

prasad agarwal
Ranch Hand

Joined: Aug 24, 2006
Posts: 44
Hi all,

Well I have got a question... I have many projects running and in all of them I have some connections to make
(not database connections but mail server, LDAP connections etc )
which i do using hard coded IP address, user ID and pwd. Recently a change was requested in those variables and I
ended up changing them in all the projects.

I just thought maybe I should be doing this in a better way. Do it all in one place and call the same code which
returns these values. Well I need your suggestions on this, I know you guys must have good ways of doing this
Some of the projects are web apps running on Websphere and some are just java projects.

Hmm,.. so how do I handle this,.. any ideas?
As of now I am thinking maybe web services or RMI , though I have not done any of these anytime...

Thanks a lot
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Hard-coding these values in code is a bad idea no matter how you do it.

Why aren't you reading these values from a properties file?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
prasad agarwal
Ranch Hand

Joined: Aug 24, 2006
Posts: 44
Thanks a lot;
Yeah in some projects I do have them in properties file, though not in all projects;
but again I need to change it in all the files when changing IP address etc right.

I am thinking maybe have these in database and in each project read from database;
so that no change is needed anywhere apart from updating database ...

Any more ideas...
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

A single properties file can be shared across multiple applications at build time.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
If there is any variables that is common between all these properties, then you can put those in one place and read dyanamically. However, if all the variables are different, even if you put them in separate properties files, you still have to change tehm all if they need to.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code reusability ideas?
 
Similar Threads
What is distributed Computing from an Application's Point of View
Building small web application in java for practice.
How to close Hibernate C3P0 Connections properly?
Is this even possible?
Does anyone else use index cards?