Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80060
| From | Rob Gaddi <rgaddi@technologyhighland.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Classes |
| Date | 2014-10-31 14:40 -0700 |
| Organization | Highland Technology, Inc. |
| Message-ID | <20141031144045.05965228@rg.highlandtechnology.com> (permalink) |
| References | (3 earlier) <5453c1a6$0$12981$c3e8da3$5496439d@news.astraweb.com> <7pg75alj1qn97hlirk81f7nqd265emgu05@4ax.com> <20141031104319.02e1ca6f@rg.highlandtechnology.com> <mailman.15370.1414788668.18130.python-list@python.org> <b90013c1-e27f-430a-8791-1f6da6e024e6@googlegroups.com> |
On Fri, 31 Oct 2014 14:24:11 -0700 (PDT) sohcahtoa82@gmail.com wrote: > On Friday, October 31, 2014 1:51:23 PM UTC-7, Chris Angelico wrote: > > On Sat, Nov 1, 2014 at 4:43 AM, Rob Gaddi > > <rgaddi@technologyhighland.invalid> wrote: > > > Define a Square class, subclassed from Rectangle. Use getters/setters > > > to enforce that the length and width must be equal. Confirm that > > > length and width remain locked, and that perimeter() and area() work > > > correctly. > > > > Here we go again... > > > > http://en.wikipedia.org/wiki/Circle-ellipse_problem > > > > Square and Rectangle are just as "obviously" the other way around in > > the hierarchy, and it's wrong whichever way you do it. Not a good > > example. > > > > ChrisA > > I've never heard of the Circle-Ellipse problem, and my first instinct to Rob's post was to ask, why would you want to sub-class Rectangle into a Square class? A square is just a special case of a Rectangle. Attempting that kind of sub-classing would just cause problems. The only thing you gain is a slight optimization in calculating perimeter by turning two multiplications and an addition into a single multiplication which really wouldn't have an effect on performance unless you were doing that calculation millions of times per second. As a practical tool? Entirely and completely useless, no doubt about it. But it's easily understood as an example, even if the reason that a Square is a subclass of Rectangle is "because I said so". For this specific exercise, a Square is a subclass of Rectangle because the point of Rectangle is to demonstrate that extraneous get/set functions are completely unnecessary in Python. The point of Square is to demonstrate that get/set functions can be useful in certain circumstances where you need to implement non-trivial behaviors, such as making the "width" property into an alias for the "length" true data member. As a learning tool for thinking about inheritance hierarchies it's kind of rubbish. But then again, most inheritance hierarchies are ambigious at best, which is why "has a" is often a better choice than "is a". -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 16:16 -0400
Re: Classes sohcahtoa82@gmail.com - 2014-10-30 13:33 -0700
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 17:00 -0400
Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-30 13:34 -0700
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 17:00 -0400
Re: Classes Larry Hudson <orgnut@yahoo.com> - 2014-10-30 14:28 -0700
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 17:34 -0400
Re: Classes sohcahtoa82@gmail.com - 2014-10-30 18:21 -0700
Re: Classes alister <alister.nospam.ware@ntlworld.com> - 2014-10-31 09:59 +0000
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 10:07 -0400
Re: Classes "ast" <nomail@invalid.com> - 2014-10-31 10:05 +0100
Re: Classes "ast" <nomail@invalid.com> - 2014-10-31 10:18 +0100
Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-10-31 20:21 +1100
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 10:05 -0400
Re: Classes Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-31 08:47 -0600
Re: Classes Grant Edwards <invalid@invalid.invalid> - 2014-10-31 15:49 +0000
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 12:31 -0400
Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 03:37 +1100
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 12:47 -0400
Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 04:02 +1100
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 13:31 -0400
Re: Classes Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-31 12:39 -0500
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 13:57 -0400
Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-31 10:40 -0700
Re: Classes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-01 11:17 +1300
Re: Classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 12:06 +1100
Re: Classes Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-01 00:12 -0600
Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 17:32 +1100
Re: Classes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-03 00:32 +1300
Re: Classes Dave Angel <davea@davea.name> - 2014-10-31 13:20 -0400
Re: Classes Marko Rauhamaa <marko@pacujo.net> - 2014-10-31 19:35 +0200
Re: Classes Grant Edwards <invalid@invalid.invalid> - 2014-10-31 17:40 +0000
Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-31 18:26 -0400
Re: Classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 12:09 +1100
Re: Classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 04:06 +1100
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 13:18 -0400
Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-31 10:43 -0700
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:18 -0400
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:42 -0400
Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-31 18:57 -0400
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 19:22 -0400
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 19:32 -0400
Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-01 12:00 -0400
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-01 12:42 -0400
Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-02 09:50 +0000
Re: Classes Tim Delaney <timothy.c.delaney@gmail.com> - 2014-11-02 21:32 +1100
Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-02 12:27 +0000
Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-02 11:31 -0500
Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-03 03:12 +0000
Re: Classes Dan Sommers <dan@tombstonezero.net> - 2014-11-03 06:29 +0000
Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-04 01:10 +0000
Re: Classes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-04 18:30 +1300
Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-03 08:50 -0500
Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-04 02:34 +1100
Re: Classes Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-03 07:47 -0700
Re: Classes Larry Hudson <orgnut@yahoo.com> - 2014-11-02 14:03 -0800
Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 07:51 +1100
Re: Classes sohcahtoa82@gmail.com - 2014-10-31 14:24 -0700
Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-31 14:40 -0700
Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 08:56 +1100
Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 08:36 +1100
Re: Classes Grant Edwards <invalid@invalid.invalid> - 2014-10-31 17:43 +0000
Re: Classes Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-31 14:11 +0000
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 12:49 -0400
Re: Classes "ast" <nomail@invalid.com> - 2014-10-31 19:31 +0100
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:36 -0400
Re: Classes Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-31 14:41 -0400
Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:56 -0400
csiph-web