Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code reusability ideas?

 
prasad agarwal
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
prasad agarwal
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A single properties file can be shared across multiple applications at build time.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic