Downcasting - whats the problem?
From: Object Developer (ukobjectdeveloper_at_yahoo.co.uk)
Date: 05/16/04
- Next message: Alfredo Novoa: "Re: Why is OO Popular?"
- Previous message: Val: "Wich pattern (if any)?"
- Next in thread: Daniel Parker: "Re: Downcasting - whats the problem?"
- Reply: Daniel Parker: "Re: Downcasting - whats the problem?"
- Reply: Daniel T.: "Re: Downcasting - whats the problem?"
- Reply: Phlip: "Re: Downcasting - whats the problem?"
- Reply: Shashank: "Re: Downcasting - whats the problem?"
- Reply: Mark Nicholls: "Re: Downcasting - whats the problem?"
- Reply: H. S. Lahman: "Re: Downcasting - whats the problem?"
- Reply: Robert C. Martin: "Re: Downcasting - whats the problem?"
- Reply: Object Developer: "Re: Downcasting - whats the problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 May 2004 04:39:55 -0700
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:
public SomeMethod(SomeObject obj)
{
if(obj is typeof(FooClass))
{
///
}
else if(obj is typeof(BarClass))
{
///
}
etc...
}
What I cannot understand is where else downcasting is not preferred,
and why it is "bad design", which is what I seem to think most people
think it is on here. I recently read some back-posts on this topic,
and Mr Robert Martin states a valid need to apply downcasting (Vehicle
and Operator thread). However some people continued to state that
downcasting is something to avoid, even in these situations (though I
personally failed to see how you would get around it).
I am still learning object oriented development, and I am sure there
are other lurkers who would like to know some of the things that are
not said or explained. The reason for downcasting being bad design is
one of them, certainly for me.
Thanks
uod.
- Next message: Alfredo Novoa: "Re: Why is OO Popular?"
- Previous message: Val: "Wich pattern (if any)?"
- Next in thread: Daniel Parker: "Re: Downcasting - whats the problem?"
- Reply: Daniel Parker: "Re: Downcasting - whats the problem?"
- Reply: Daniel T.: "Re: Downcasting - whats the problem?"
- Reply: Phlip: "Re: Downcasting - whats the problem?"
- Reply: Shashank: "Re: Downcasting - whats the problem?"
- Reply: Mark Nicholls: "Re: Downcasting - whats the problem?"
- Reply: H. S. Lahman: "Re: Downcasting - whats the problem?"
- Reply: Robert C. Martin: "Re: Downcasting - whats the problem?"
- Reply: Object Developer: "Re: Downcasting - whats the problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|