There are hundreds of reasons to extend String. Maybe you want strings to be able to archive in a special way? Maybe you need them to be initialized from a special type?
Yes, in those cases, you could use a static helper function. Inelegant, but functional.
More importantly, there are often times when the instance implementation and the static class methods must be implemented in the same class. This is the case that I had that originally started this thread. The problem was, an existing tool took 3 parameters:
1) The class name of the instance you want to use to represent something in a database 2) The method ON THAT CLASS that generates the representation you want for the database storage 3) The static method ON THAT CLASS that can be used to initialize a new instance from database storage
There is no way to make this work without subclassing - and that is why I don't like 'final'.
Everyone - please - there are language capabilities that are good and bad depending on how you use them. There are functions people may not understand or need, while others might. I was complaining about 'final' in the midst of trying to accomplish something, not to start a debate.
Ken On Aug 30, 2006, at 3:57 AM, Marcin Lukasiak wrote: I'm saying about your design - you can always use composition instead of inheritance in your design, when class is marked as final. Still I don't see resonable case when I would like to extend String especially because it is immutable so what is the real need that you would like to extend it?
|