Re: String and StringBuilder sealed ... another WHY

From: Sherif ElMetainy (elmeteny.NOSPAM_at_wayout.net.NOSPAM)
Date: 03/26/04


Date: Fri, 26 Mar 2004 10:58:29 +0200

Hello

As mike said, Convert is also not a good example, since it exposes only
static methods, and you can make your type use convert by implementing
IConvertible interface. However I agree that sealed is sometimes
frustrating. But the post was about the String and StringBuilder classes,
where it is right to make it sealed.

Best regards,
Sherif

"Julie" <julie@nospam.com> wrote in message
news:40639148.C9AB3CD4@nospam.com...
> Sherif ElMetainy wrote:
> >
> > Hello
> >
> > Having 2 versions of a class (sealed and non-sealed) would create a lot
of
> > confusion for developers, specially with a class as common and important
as
> > the string class.
> > To make your own string maniplation methods, you can create a class with
> > static methods that manipulates strings.
> > The designers of .NET framework saw that since strings are used in
almost
> > all progams they had to be optimized.
> >
> > Best regards,
> > Sherif
> >
> > "Julie" <julie@nospam.com> wrote in message
> > news:40635402.28C06A9E@nospam.com...
> > > beutler wrote:
> > > >
> > > > Recently, I tried to extent class string (it could have much more
> > > > features), and ups - "cannot derive from sealed class string", so I
> > > > looked around in some groups, and, yes, I found every time the
comment
> > > > that classes string and even sytem.text.stringbuilders ARE sealed.
> > > > While I can understand this for class string (it is a
non-modificable,
> > > > immutuable string), I was very suprised as I see this for class
> > > > stringbuilder.
> > > >
> > > > Of couse, performance optimization is one thing, but how the hell I
> > > > could extent string funcionality of .NET ? Write a wrapper class and
> > > > forward all methods or what ? That would have to do nothing with
> > > > object-orientation, and, when learning a new language, I would not
> > > > make two steps backward in design questions...
> > > >
> > > > Sorry, but this is my first contact with C# (I'm coming from C++),
and
> > > > I'm already shocked. I'm excited what other surprises C# would bring
> > > > for me
> > > >
> > > > So please tell me, are there any further reasons why they don't
allow
> > > > to inherit from both classes, are there any other similar classes or
> > > > proposals to extent string functionality in an OO way ?
> > >
> > > I'm often frustrated w/ the same.
> > >
> > > Personally, I think that sealed leads to all sorts of problems for
users
> > of the
> > > library. My thoughts are that if a designer seals a class for
performance
> > > reasons, they should also offer a *non-sealed* version of the class
that
> > can be
> > > extended by the user, w/ the expected degradation in performance.
> > >
> > > So, if String and StringBuilder are sealed, then the designers should
have
> > > included ExtendableString and ExtendableStringBuilder that provides
for
> > > derivation.
> > >
> > > Short-sighted design in my view.
>
> String is maybe not the best example.
>
> However, consider Convert. Very useful for providing conversions from
> arbitrary to known types -- *but*, it is _sealed_. Now, if I create a new
> type, there is no way to extend Convert to support it -- meaning I have to
> create a completely new class or use some other traditional method.
>
> Chew on that and let me know what you think.



Relevant Pages