• Post Reply Bookmark Topic Watch Topic
  • New Topic

basic design question  RSS feed

 
Wesley Baker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When building a web app, what is the best way to organize a set of methods that don't really have anything in common, other than they are all frequently used by different servlets?

For instance, I have a function that calculates tax based on state, and another that prints a predefined list of error messages, and another that validates credit card numbers. All of these functions are frequently used by different servlets in different packages, and up to this point I have been stuffing them all into one class, usually with a name like "CommonUtils", or "CommonMethods". Is this common practice, or is there a better way to organize these? Should I really have a separate class for each of these, since they have different purposes and no commonality?
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wesley Baker wrote:Should I really have a separate class for each of these, since they have different purposes and no commonality?

Yes. Calculating tax based on state is business logic. A case could be made that validating a credit card number is also business logic, so you might put those together in a class named something like BusinessRules. Printing an error message is a UI task that belongs as far away from those logic methods as you can get it.
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the tax method in a Taxes class. Make a simple CreditCard class. And why would you want to print a list of predefined errors at all?
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm with Stephan on this. A CommonUtils class with methods that do things like validate credit card numbers and calculate taxes sounds a lot like procedural-style Java code rather object-oriented code. BusinessRules is too generic a name for my taste and indicates a lack of understanding what exactly the rule(s) is(are) or a lack of effort in finding a more descriptive name.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!