Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I wonder why java defines homogeneous methods in two distinct classes: java.util.regex.Pattern and java.util.regex.Matcher.

For example split method defined in Pattern class and replaceAll method defined in Matcher class. I think these two methods are homogeneous, why are they not defined in the same class?

Have I understood it wrong?

By "homogenous", I mean: split and replaceAll methods are utilities for String, why not defined in a class?

share|improve this question
    
What do you mean when you say "homogenous"? I don't understand the question. –  Michael Borgwardt Mar 5 '12 at 8:51
    
My means is: split and replaceAll methods are utilities for string, why not defined in a class? –  MJM Mar 5 '12 at 8:55
1  
I'm guessing it is for historic reasons, but maybe someone knows the specifics. –  Garrett Hall Mar 5 '12 at 15:02
    
@GarrettHall maybe this opinion is correct. –  MJM Mar 5 '12 at 15:37
add comment

2 Answers

up vote 1 down vote accepted

I'm guessing there's a or more historical reasons because you say correct, those classes have homogenous methods.

share|improve this answer
add comment

Not certain to be right, but :

When you create a regex, you have to cut/look inside the object you are searching for.
You have to know how it is made : you make a tool (split()) to detect the Pattern you like.

But when you use this tool, you want to make it usefull, so each time your pattern matches, you apply the rule pre-defined (replaceAll()).
How can you apply it if you do not know on what, this is not the same gesture/movement, so not the same class?

Forget you are a programmer and enrole you like an artisan, if now it is not obvious, find another point of view.
It is an language problem, each person have its meaning of words, often it is the same between them, sometime not, you have to guess what is behind the words wrotten which perturb your analysis.

Good 'declic'

Best regards Claude

share|improve this answer
    
Thanks for your answer, please more explain. –  MJM Mar 5 '12 at 15:13
    
Sorry about the lateness :I've not seen the tool 'inbox', I discorver it today. I tried to say : you see those classes homogeneous, detect their different behaviours, so you can apply a method to one, and the other to the second. One is the touchstone/give the law, the second the tool to compare/react face to a situation --> in OO things different have classes different -?- Not certain to be more understandable. –  cl-r Mar 26 '12 at 15:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.