Re: Some thoughts about OO programming
From: MSCHAEF.COM (mschaef_at_io.com)
Date: 10/07/04
- Next message: Programmer Dude: "Re: Beginner, Which language"
- Previous message: DEMAINE Benoit-Pierre: "Re: open soucre project"
- In reply to: TGOS: "Some thoughts about OO programming"
- Next in thread: TGOS: "Re: Some thoughts about OO programming"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 07 Oct 2004 08:46:14 -0500
In article <90a4dba897d8c925e9c1cf15c0214625@localhost.talkaboutprogramming.com>,
TGOS <spamcop@_nospam_tgos.net> wrote:
>I like OO programming... in general, but the concept has several flaws.
What concept doesn't have flaws?
>I
>tried to fix these by simply creating an own OO language just as a proof
>of concept, that it's possible to create an OO language without all these
>flaws.
Can you post more information on what you've done so far? I think it'd
probably make for interesting reading.
>Animal -> Bird -> Penguin
>Animal -> Bird -> Ostrich
>
>Assume Anmial has a method canFly().
>
>animal.canFly() is abstract
I'd rather put a method 'fly()' in Bird, to avoid the problem you mention.
Asking animals if they can fly is the logically the same as switching on a
type code which is exactly what polymorphism is supposed to help fix.
>OO Programming means: You either can't ever add methods to an object or
>all sub-classes must be under your control. The second other people build
>their work on top of your work, you break their work by modifying any of
>your classes.
Yeah, in general that's called the fragile base class problem. It's one of
the reasons people tend to like interface inheritance, etc. rather than
implementation inheritance. With that, your library provider might give
you an interface to code against:
interface IAnimal
{
// ...whatever...
bool canFly();
}
A later version of the library might also offer
interface IAnimal2 : public IAnimal
{
bool canSwim();
}
Then, objects can implement either one or the other. If the library can
tell that an object doesn't implement IAnimal2 it can then proceed knowing
that the object doesn't know if it can swim or not.
Another reason this is beneficial is that the fragile base class problem
extends to things like class layout. That is, if I give you an object
library and you compile against it, the code the compiler emits for yor
code is going to be full of assumptions like The _foo field of the Bar
class is at offset 48 from the beginning of the object. If I add a field
to a base class in my library, that can change the offset of _foo and
require all code that links against my library to be recompiled.
>Going by OO logic, all manipulations to an image are supposed to be
>methods of Image.
That's not necessarily true. It's perfectly possible to define tool
objects that can manipulate images. Rather than saying this:
Image img = new Image("foo.bmp");
img.GaussianBlur(12);
You might say this:
Image img = new Image("foo.bmp");
GaussianBlurFilter filt = new GaussianBlurFilter(12);
filt.apply(img);
If you want to draw on an image, you might ask it for a canvas object that
provides a set of drawing operations. There are a bunch of different ways
to avoid creating so many methods in an object. There are also a bunch of
reasons to avoid it, many of which you address in your post.
>fracImage = new FractalImage((Image) geogrImage);
>
>and then I want to store it as JPEG:
>
>jpgImage = new JPEGImage((Image) fracImage);
>
>And inside the whole picture data is always copied around... surely, this
>will result in fast application...
Not necessarily. It's pretty easy to use techniques like copy-on-write
to minimize this. You might end up with new instances, but they'll share
most of the same representation until there's a good reason for them not
to.
-Mike
-- http://www.mschaef.com
- Next message: Programmer Dude: "Re: Beginner, Which language"
- Previous message: DEMAINE Benoit-Pierre: "Re: open soucre project"
- In reply to: TGOS: "Some thoughts about OO programming"
- Next in thread: TGOS: "Re: Some thoughts about OO programming"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|