Re: Downcasting - whats the problem?

From: H. S. Lahman (h.lahman_at_verizon.net)
Date: 05/18/04


Date: Mon, 17 May 2004 23:53:59 GMT

Responding to Developer...

> I would like to ask what will be a very basic question for many on
> this list, so I hope those people offer some helpful advice on this.
> I would like to understand what the real problem is with downcasting
> in a staticly typed language. I know about the OCP, and I understand
> the reasons for why this type of thing is wrong:

The basic problem with downcasting is that it is treating an
non-navigable relation as if it were a navigable association. An OO
is-a relation is not navigable because there is only one instance in
hand that resolves the entire tree. IOW, there is no to/from to navigate.

In addition, accessing subclass specialization through the superclass is
a no-no that defeats the point of restricting access to properties.
When one accesses a superclass one is only supposed to be able to access
the properties that the superclass makes available. If one needs to
access subclass specializations, there should exist a relationship
directly to the subclass that can be navigated for access to those
properties.

          1 R1 1
[Client] ---------------- [Super]
                           + doCommon()
                              A
                              | R2
                   +----------+----------+
                   | |
                 [SubA] [SubB]
                 + doA()

[SubA] and [SubB] must provide implementations for doCommon(). If the
solution requires Client to access doCommon() behavior all is well
because that responsibility is exposed in [Super]. That is, Client
navigates R1 -> Super to access the behavior.

However, if a Client must access the doA() responsibility, it can't do
that by "navigating" R1 -> Super -> R2 -> SubA to get to SubA. To
access that specialization it needs a path directly to [SubA]:

          1 R1 1
[Client] ---------------- [Super]
    | 1 + doCommon()
    | A
    | | R2
    | R3 +----------+----------+
    | 1 | |
    +----------- [SubA] [SubB]
                 + doA()

so that it can navigate R3 -> SubA.

*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
(888)-OOA-PATH



Relevant Pages

  • Re: Visitor, dynamic_cast or ...
    ... >>This yields a fairly simple and efficient view of the tree that doesn't ... >>concerns of tree navigation from leaf processing (i.e., ... the client knows what type it will have in hand prior to actually ... OcTree to navigate to either specialization directly; ...
    (comp.object)
  • Re: Page Load event is called....
    ... > the life cycle of every page, ... > instructing it (the client) to open a different page instead of the one ... > server and skips the additional HTTP request but neither method will ... >> always happen when I navigate to the next page. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Downcasting - whats the problem?
    ... > Responding to Developer... ... >> I would like to ask what will be a very basic question for many on ... there is no to/from to navigate. ... > However, if a Client must access the doAresponsibility, it can't do ...
    (comp.object)
  • Re: Cannot access Previous versions from Win2K
    ... I rolled the previous versions client to all of our clients and then checked ... that the previous versions tab appears when the user right clicks on a file ... My problem is that when i navigate to a file using win2000 SP4 which has ... >> If i navigate to the same place on an WinXP client the folders appear.. ...
    (microsoft.public.windows.server.general)