TIP: Click on subject to list as thread! ANSI
echo: public_domain
to: Paul Edwards
from: Paul Markham
date: 1995-09-28 20:17:36
subject: object oriented c

PE>> With great difficulty, which is why I don't allow constuctors to fail.



 PM>> Since you're using C and not C++, you must call your constructor

 PM>> explicitly. Therefore you can test the return value all of the time.



 PE> And thus be incompatible with C++.  My Defaults() is equivalent to

 PE> a C++ constructor.  My Init() is equivalent of having a C++ function

 PE> called Init() which is always called at runtime.



As I said, a C++ constructor can fail, therefore you aren't being
compatible with C++ anyway. All you've effectively done is to split the
constructor into two parts - Defaults() and Init(). To properly initialise
your class into a useable state you have to call both of them.



 PM>>> It's not just updating the members of a structure I'm trying to

 PM>>> discourage, it's also reading them and relying on things that may

 PM>>> change. One of the tenets of OO is that the interface
should remain the

 PM>>> same, but the implementation can change.



 PE>> When was the last time you saw a program that relied on the internals of

 PE>> the FILE data structure?  So long as you document the interface, which

 PE>> fopen(), fgets() etc do, it's people's only silly fault for looking

 PE>> inside the FILE data structure.



 PM>> Why do you think OO languages have the concept of private data?



 PE> For Cobol programmers?  I don't know.  That's done quite successfully

 PE> in C already, as the FILE data type demonstrates.  If you need to

 PE> protect programmers from themselves, you've hired the wrong

 PE> people in the first place.  BFN.  Paul.



As a Real C Programmer, I suppose you don't bother with function
prototypes, you ignore those pesky warning messages the compiler insists on
spitting out and you'd never consider running Lint over your code. After
all, Real C Programmers don't need to be protected from themselves.



The point of all of the above things and OO techniques such as
encapsulation, *is* to protect the programmer from themselves. The end
result is, hopefully, a more robust and error free program.





Paul



--- GoldED/2 2.42.G0214+

* Origin: It's not even a nice place to visit (3:711/934.1)
SEEN-BY: 690/718 711/809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.