On Fri, 06 Jul 2007 14:16:42 -0700, Michael Thompson
<su*****@totalstream.comwrote:
I am new to .Net and OOP techniques; I am not even certain that I using
the correct terminology here.
I believe that I want to know how to do inheritance.
You may find these pages helpful:
http://msdn2.microsoft.com/en-us/library/ms173109.aspx http://msdn2.microsoft.com/en-us/library/ms173149.aspx
You can easily do what you describe using inheritance. Though, you may
find that if that's the only method you intend to add, it's overkill to
create a whole new class, especially since to use it would mean either
replacing every use of "string" with "TSTString", or creating a whole new
"TSTString" instance any time you wanted to call that method. Neither
seem like particularly inviting scenarios to me, just to do one thing.
Note also that to make the inherited class most useful, you would want to
create new constructors with all of the same semantics as those that exist
for the String. There are a bunch of them, and without creating them, you
may well run into situations where you are forced to instantiate the base
String class just for the purpose of instantiating the derived class
moments later.
If you have a whole bunch of new functionality you want to add to the
String class, then the above may all be worthwhile and making a new class
that inherits String might make sense. But otherwise...
If all you want to do is be able to create a method called "ProperCase()"
that does something with a string and returns a new one, you may be better
off just creating that as a static method in some other class you've
already got (or create a new class where you put this sort of utility
method). You'll avoid all the inefficiencies that inheritance would cause
in this case.
Note that you should still learn about inheritance. It is often exactly
the right thing to do. I'm just saying that in this case, the example
seems sort of contrived and may not lead to better code by inheriting the
String class.
Pete