"Nels Olsen" <nels@oncontact.com> wrote in message
news:6FC4A7F6-F0FA-476B-8789-D62C085FA41D@microsoft.com...[color=blue]
> Yes, the lack of a "virtual" keyword on a base class member does insure[/color]
that a base class reference containing a subclass instance will access the
base class's member, in the situtation where the subclass has a member with
the same signature, but that's not our problem (or, more correctly, the mad
prefix-happy camp's worry -- what follows below I do not even consider a
problem, but I still have to neutralize the issue ...)
Lucky you. :)
[color=blue]
> Say you have a base class from a 3rd party toolkit called CircusPerformer.[/color]
Your company is making a product with a public API, and it has it's own
"base" class wrapper, OurCircusPerformerBase, and several subclasses
(HighWireWalker, Clown, etc -- details not necessary). You notice that in
releaase 1 of the 3rd party toolkit, there's no method called Juggle. You
wonder why they didn't put it in their base class, since many of the
different performers juggle during their act. So, you add Juggle to
OurCircusPerformerBase. You release our product and its public API.[color=blue]
>
> A year later you get release 2 of the 3rd party toolkit. They finally got[/color]
around to adding Juggle to their CircusPerformer base class. Potential
problem:[color=blue]
>
> If your Juggle method returns a different datatype than the 3rd party's[/color]
Juggle method, will your code even recompile? I don't know. Are you forced
to change the name, or change the return type (withdrawing that signature
from your API)? This is probably more likely with properties than
methods -- e.g. the toolkit has a type called Thingy, your API subclasses it
as OurThingy, you subclass a toolkit base class and add a property
DefaultThingy as type OurThingy, then the toolkit adds a property to the
base class called DefaultThingy as type Thingy.
Sure, it will compile. The return type doesn't cause any problems in
hiding, but will cause a compiler error if you want to override a new
virtual base class method. Properties that don't override will hide
regardless of their type, but different return types will cause a compiler
error when trying to override a virtual base class property.
[color=blue]
> Even if there is no "hard" collision (i.e. the code still compiles, with[/color]
base class references and subclass references getting the correct member at
runtime), there still may be "confusion" to developers. If
OurCircusPerformerBase's idea of Juggle is somewhat different, new API users
familiar with the raw 3rd party CircusPerformer.Juggle behavior may be
confused when they invoke Juggle on a OurCircusPerformerBase reference,
expecting the 3rd party toolkit behavior. To this concern I say RTFM, but
our market is oddly toward "non-technical" people wanting to make "quick and
easy" customizations to our product through our API (or wizards that will
generate the code for you). The mad prefix-happy camp wants to put an
abbreviation of our company name on EVERY public method, property and event
in our API's classes, so that even "soft" collisions will not occur
(assuming the toolkit manufacturer doesn't take up the same naming scheme
....)
Where I see the prefix convention breaking down is when you really do want
to override members of the 3rd party base class, which will make your API
inconsistent. If you are using composition, I don't believe there will be
any technical problem.
Joe
--
http://www.csharp-station.com