[1657] in java-interest
Re: extending string functionality.
daemon@ATHENA.MIT.EDU (David Geary)
Wed Sep 13 14:01:32 1995
Date: Wed, 13 Sep 1995 08:21:20 +0700
From: David.Geary@Central.Sun.COM (David Geary)
To: java-interest@java.Eng.Sun.COM
> From daemon@java Tue Sep 12 21:41 MDT 1995
> Date: Wed, 13 Sep 1995 12:59:33 +1000
> From: Graham Matthews <graham@pell.anu.edu.au>
> To: java-interest@java
> Subject: extending string functionality.
> X-Info: To unsubscribe, send 'unsubscribe' to java-interest-request@java.sun.com
>
> I have a Java Language question. It probably has a simple answer, but I
> have not found it.
>
> I have a collection of string parsing routines written in a language called
> Python (these routines don't change the strings in any way, rather they
> return information from within the string (eg. maximal length substrings
> satisfying patterns, etc). Now I have translated them into Java, and would
> like to allow them to be user on Java Strings (i.e. objects of class String).
> There does not seem to be a convenient way of doing this however.
>
> I first tried to put all these routines in a file, and just compile up
> that file. That didn't work as it seems that all routines have to be
> inside class definitions (ie. have to be methods).
>
> So I thought I would extend class String - can't do that since there are
> no extension mechanisms (other than subclassing in Java).
>
> So I thought I would subclass String, making a class MyString, which
> contained my routines, and which inherited the String methods. Can't do
> that since String is final.
>
> There seems to be no way to add my routines to the existing functionality
> of class String.
How about a StringParser class? You would probably associate a given String
with each StringParser; StringParser's constructor would take a String.
I see very little need to treat Strings and StringParsers polymorphically.
However, if you do, you can always use the decorator pattern, which
allows you to attach additional responsibilities to an object dynamically.
See the discussion in 'Design Patterns by Gamma/Helm/Johnson/Vlissides'.
BTW, if I were implementing such a StringParser in C++, I would disallow
default construction. Does Java allow disallowing of member functions?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
David Geary "Look where all this talking got us, baby"
geary@rmtc.Central.Sun.COM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com