• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling single class multiple times  RSS feed

 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how we can call one class in multiple programs to reduce code redundancy
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean calling methods of a class?

Classes may be instantiated or subclassed; it is the methods that are called. Yes, they can be called multiple times. And yes, you can instantiate a class in multiple programs, depending upon its visibility ( determined by access specifiers ) and the visibility of its constructors.
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i have one class


and this is my servlet so what i wat is that all the connections with database i want to call in deleteservlet .how can i do that.i dont want to write connections repeatedly
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should different modules for different purpose. For e.g. DataHelperClass this can be used for handling database related functionality like making connection, handling queries, returning resultset etc. You can have another class like StringUtils that performs String related functionality like checking for empty, checking for numeric values etc. For a web application if you are following MVC you should a single servlet handling all the requests. Servlet will do the necessary computations using the helper classes as I mentioned above and render the output to jsp.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Standard OO programming,reusing things in a modular method. That mehtod looks like a 1368 in the most dubious classification of methods known to Science. You should therefore consider making it static. You should also consider moving the database connection code; it seems inefficient to create a new connection every time you have a name to validate.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!