chrisname wrote: |
---|
FILE* is just a struct (probably typedef struct file { ... } FILE; or similar). fopen, fread, fwrite, fclose and friends just operate on the members inside the struct. Then it uses syscalls or the system API to actually operate on the file. |
Yes yes. I know all this.
It's written in C, so of course it's only going to have C constructs. How it's implemented doesn't matter, it's what it
does and how it's
used that is what makes it OOP.
The point here is it represents an
abstract concept and can do two (or more) entirely different things depending on the type of FILE you have.
Outputting to a console, and outputting to a file are two very different things. Yet FILE and friends let you do it with the exact same interface. This is like the exact definition of an abstract base class. Only C doesn't have abstract base classes as a language feature, so instead it implements it through a pointer to a black-box structure.
It doesn't matter if FILE's implementation doesn't have any function pointers.
It doesn't matter if FILE doesn't have any special cases for stdout
What matters is that at some point down the line, different code is going to be necessary to write to the console vs. write to the screen. I mean these are two clearly different tasks. There's no way they're accomplished exactly the same way.
Yet to the person
using FILE, the differences are unnecessary to know because FILE treats it all the same way.
I don't why you guys don't see it. This just screams polymorhpism to me. Maybe I'm just crazy. =P
As for the whole UNIX file descriptor thing, I guess that would mean that FILE in that instance isn't polymorphic, but it takes advantage of the file descriptor's polymorphic behavior.