Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!psuvax1!rutgers!aramis.rutgers.edu!topaz.rutgers.edu!mccarrol From: mccarrol@topaz.rutgers.edu (Mark C. Carroll ) Newsgroups: comp.object Subject: Re: OOP in C Message-ID: Date: 7 Dec 89 18:15:53 GMT References: <3356@hydra.Helsinki.FI> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 80 In article <3356@hydra.Helsinki.FI> jokiniem@cs.Helsinki.FI (Jari Jokiniemi) writes: ]We are doing some research on transaction processing on heteroneneous ]distributed databases. We have implemented our demo programm using ]C language with very conventional programming techniques. ] ]There has been some discussion that one can use object oriented programming ]techiques even when writing the programm with any conventional language. Since ]the concept of what these OOP techniques really are in practise is not well ]explained in any book we've found, the very idea of OOP has remained ]fuzzy for us. ] I'm going to post another message with a programming project. Before I do it, I'm going to explain what I mean by OO in my C programming. To me, the basis of Object Oriented programming as I use it in C is a sort of excapsulation: I try to hide the internal structure of my data as much as possible. I define abstract data types by a set of functions that access them. The actual internal structure of the data is hidden, in favor of a set of functions that allow access to the data. So, for example, I define a linked list: typedef void *generic; typedef int boolean; typedef struct list_struct { struct list_struct *next; generic *data; } *list; Then, I define the set of structures that are allowed to access my list: list list_New(); boolean list_Insert(generic);/* returns success flag */ boolean list_Remove(generic); boolean list_Find(generic); Now, all access to be lists is done through this set of functions. I don't ever look at the inside of this structure; I always use this set of functions. I assume that the list will be homogeneous, or I'd define a new type for the data field, which had some way of identifying it's type, and some functions to access that field. ]Therefore I ask some help from the netlanders. Would someone ]give some examples written in C or some other conventional language ]about what OOP is in practice. We are especially interested in what ]data structures are needed, why they are needed, and what benefits may ]we gain by using them instead of some other alternatives. We can not ]change the programming language, and that is why examples written in C ]would be the ones mostly needed. ] I'll post an example of a b-tree assignment I wrote for a class. It's not a perfect example of thi style, but it should give you an idea. The advantages of programming this way are: + Ease of debugging: when all access to the structure is localized, it's much easier to find the bugs. You can be sure of noone mucking about with the internal structure of your data. + Consistency: you always know exactly how people are going to use your code. + Reusability: if you keep to a tight, abstract data structure, the code for that structure can be used easily in any other program. + Organization: I find that code that I write this way is much, much easier to read, understand, and debug that code written in a less highly structured fashion. + discipline: programming this was forces you to be more disciplined. You have to clearly think things out in order to start writing a program this way. ]Jari Jokiniemi / / Technical Research Centre of Finland: -- \ Mark Craig Carroll: \ "Don't ever think that you can't \ Student Systems Programmer - LCSR \ change the past and the future" \ Rutgers University \ -Kate Bush \ mccarrol@topaz.rutgers.edu \ (standard disclaimer applies)