I am currently writing a program that turns a String into an int I got my own rules example : ("37dsqff" = 37) ("50 km/h" = 50) The problem is the String can be any kind (StringBuffer, Vector, InputStream...) and i don't have any control on it.
So far I have made 1 parseInt() function for each one. It looks this way :
public class Tools {
public static int parseInt(StringBuffer s)
{
...
return n;
}
public static int parseInt(Vector<Character> v)
{
...
return n;
}
....
}
I have noticed that every functions share too much similarities and I would like to use a design pattern to make it better and only have 1 parseInt function
I think about Visitor, template method but i don't know what s the best here.
Aucun commentaire:
Enregistrer un commentaire