Loading ...
Sorry, an error occurred while loading the content.

Re: [XP] Circle/Ellipse dilemma

Expand Messages
  • J. B. Rainsberger
    ... Yes, but it blows the Decorator pattern out of the water. -- J. B. Rainsberger, Diaspar Software Services http://www.diasparsoftware.com :: +1 416 791-8603
    Message 1 of 120 , Nov 30, 2003
    • 0 Attachment
      Michael Feathers wrote:

      > KR> This really has nothing to do with XP.
      >
      > Here's food for thought.. if you have a class hierarchy where you
      > have only one definition for each method (no overrides) you
      > dramatically reduce your chances of an LSP violation. See why?
      >
      > I guess having more than one definition for a method is a kind of
      > duplication, eh?

      Yes, but it blows the Decorator pattern out of the water.
      --
      J. B. Rainsberger,
      Diaspar Software Services
      http://www.diasparsoftware.com :: +1 416 791-8603
      Let's write software that people understand
    • Keith Ray
      ... example of bad OO: class point { float x, y (and methods...) }; class circle extends point { float radius; (methods treat inherited x,y as center) };
      Message 120 of 120 , Dec 2, 2003
      • 0 Attachment
        On Tuesday, December 2, 2003, at 05:08 PM, Amir Kolsky wrote:

        >> Indeed, the data structure that represents an ellipse has too many
        > variables to efficiently represent a circle.
        >
        > Yup, and by virtue of the bad smell, we should know that there's
        > something immutably wrong with even trying to get to a circle by
        > subclassing ellipse...

        example of "bad" OO:

        class point { float x, y (and methods...) };

        class circle extends point { float radius; (methods treat inherited x,y
        as center) };

        class ellipse extends circle { point secondLocus; (methods treat
        inherited x,y as first locus) };

        class square extends point { float sidelength; (methods treat inherited
        x,y as top-left of square) };

        class rectangle extends square { float otherSideLength; (ad nauseum) };

        --
        C. Keith Ray
        <http://homepage.mac.com/keithray/blog/index.html>
        <http://homepage.mac.com/keithray/xpminifaq.html>
        <http://homepage.mac.com/keithray/resume2.html>
      Your message has been successfully submitted and would be delivered to recipients shortly.