Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beginner Question

 
Marco Paul
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am slowly trying to wrap my head around the dynamics of design patterns, and I was curious if the following makes sense. A class in one of our applications has nothing but helper methods that perform regular expression validations. To me, this code is a little clugy to look at and I was wondering if using a factory would make sense in this scenario. Here is a code example i was thinking:



does something like this make any sense or am i thinking to hard about this.

Thanks!
[ January 25, 2005: Message edited by: Marco Paul ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco,
What does the code look like now:

Personally, I would leave it alone. These are true utility methods, so I don't see the benefit of abstracting the classname away.
 
Marco Paul
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't the original developer of the class, but here is an example of some of the method definitions in the class:

 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt that's Java... It reads like C++
 
Udayan Patel
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen Wenting:
I doubt that's Java... It reads like C++


No it could be java, when Regular Expressions weren't available.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java? With "bool" and "string"... For me, it has "C#" written all over
 
Udayan Patel
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops, i missed bool and string part. ah! even method names starts with uppercase. Well but then patterns are suppose to be language independent.
[ January 26, 2005: Message edited by: Udayan Patel ]
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco, if you think about it, your change would replace a single simple statement with two statements wherever a validation was used. That does not seem like and improvement to me, in either C++ or Java.
 
Marco Paul
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for your help!
 
Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marco Paul:
Hello,
I am slowly trying to wrap my head around the dynamics of design patterns, and I was curious if the following makes sense. A class in one of our applications has nothing but helper methods that perform regular expression validations. To me, this code is a little clugy to look at and I was wondering if using a factory would make sense in this scenario. Here is a code example i was thinking:



does something like this make any sense or am i thinking to hard about this.

Thanks!

[ January 25, 2005: Message edited by: Marco Paul ]


Factory Pattern is used to return one of any of its sub class objects based on the given condition. I am not sure that your code will fall in this category.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic