r91400@memqa.uucp (Michael C. Grant) (07/06/90)
In article <RFROST.90Jul5222839@spam.ua.oz.au>, rfrost@spam.ua.oz.au (Richard Frost) writes: > I read some articles in a journal a while back, which discussed how to > implement OOP with standard C, I would be pleased if anyone could explain > their attempts and successes in this area. I haven't done much of my OWN OOP, but I can tell you that, in my opinion, the object-oriented approach taken by SunView, the graphical interface found on the Suns (at least the ones without X), is a breeze to program. SunView hides all of its opaque data structures by providing the user only with a pointer which has been cast to caddr_t (character address). In other words, you can't access a structure p by using *p; that would give a meaningless string of characters--hence, an effective method of information hiding! In order to operate on these opaque structures, you are provided with several general purpose routines, and a TRUCKLOAD of macros. Most of the functions accept a variable number of arguments, the first being the object pointer, and the rest being a list of pairs of command-macros and arguments: window_set(Clocks,WIN_ROWS,123,WIN_COLUMNS, PANEL_BOLD,TRUE,0); The ending 0 is the necessary sentinel to mark the end of the arguments. Now, this example shows a 'write only' function; in order to GET info from a structure (in this case, a window), you might write x_temp=(int)window_get(Clocks,WIN_X); Notice that you have to typecast the function, because it handles EVERY possible data type that the window can return! I sure wish I knew how they implemented that function... It sounds like SunView takes advantage of C's weak type checking, but hey--in my opinion, more power too them: what else were they to do? Michael C. Grant