Jump to content

Talk:Polymorphism: Difference between revisions

How to change, and another suggestion
(Circle and Point both deriving from Printable looks better to me)
(How to change, and another suggestion)
Line 70:
 
:'''Agree''' Circle derived from Point is poor design in this case, which might confuse the issue for the casual reader. The fix of having a common Shape subclass or interface looks much better to me. (In fact "Printable" would be a better name in the example above.) If you want to show off [[Inheritance]], perhaps split it into a different task. --[[User:IanOsgood|IanOsgood]] 13:01, 3 November 2008 (UTC)
:The Circle/Point idea is a problem now that I look at it. I'm not sure what the best way is to go about making the change to the Shape/Circle idea, though. The simplest idea (planning-wise) is to just start the task over. I don't think marking these examples as incorrect would be very good (since some may never be fixed). There are probably better ways to do this change...
 
:Ever better may be a slightly more complex inheritance tree. Maybe something like this:
<pre> Car
/\
/ \
/ \
Porsche Pinto</pre>
:There could be a "start" method in each class. For Car, it could print "vroom vroom", Porsche prints "go, baby, go!", and Pinto prints "clunk clunk". Then make a collection of Car objects (one Car, one Pinto, and one Porsche) and call the start method on each one for proof. Is that an OK idea or is it too complex?--[[User:Mwn3d|Mwn3d]] 16:31, 3 November 2008 (UTC)
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.