From -6423213517715727647
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8c9f1307b83ac2db
X-Google-Attributes: gidf78e5,public
From: Mark Wilden <Mark@mwilden.com>
Subject: Re: Q: virtual functions not overridable anymore?
Date: 1997/09/11
Message-ID: <34172B24.38DE@mWilden.com>#1/1
X-Deja-AN: 271444433
References: <01bcb109$1e790180$433574cf@worldnet.worldnet.att.net> <3404A0AE.6F7E@Eng.Sun.COM> <5uimip$l56@bgtnsc03.worldnet.att.net> <340D93AA.643A@Eng.Sun.COM> <01bcb951$ea80a440$909c389d@mtayler> <ocr4t7zlk2o.fsf@ml.com> <5v1i5j$qrg$1@mail.pl.unisys.com> <5v52rv$id@bgtnsc03.worldnet.att.net>
X-Original-Date: Wed, 10 Sep 1997 16:20:04 -0700
Originator: fjh@mundook.cs.mu.OZ.AU
Organization: The Mark Wilden Company
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBNBc1EOEDnX0m9pzZAQE1xAGAizZaenPREXU0njInZF+klhYl9RyDqGwB EIakv3gtyi1SdCgj0osXH74751IHcN0n =eQzr
Newsgroups: comp.std.c++


Cristian Georgescu wrote:
> 
> Suppose you have a class Apple with a virtual function getColor(); then I
> want to make a derived class GreenApple with getColor that will always
> return Green.

Since this would (probably) be a bad class design in the first place,
maybe there's a better example?

I can't think of a good use for GreenApple that couldn't better be
served simply by

 struct Apple {
    enum Color { Green, Red };
    Apple(Color, double price);
    Color getColor() const;
    double getPrice() const;
 private:
    const Color color;
    const double price;
 };

Classes should reflect behavior, not attributes--if only to avoid a
combinatorial explosion of subclasses from the union of all possible
attribute values.

I think a better example would make your point clearer.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]



