TweetFollow Us on Twitter

Learning to Love SOM
Volume Number:11
Issue Number:1
Column Tag:Foundation Technology

Learning To Love SOM

Choosing it for OpenDoc was a no-brainer

By Jens Peter Alfke, Apple Computer, Inc.

The System Object Model (SOM) provides the object-oriented substrate used by OpenDoc and by future versions of the Macintosh Toolbox. SOM is fairly complex, relatively new on the Mac, and competes against other proprietary object models. It’s not surprising, then, that there is some degree of apprehension and misinformation surrounding it. In this article, I will give you the straight scoop on SOM.

Frankly, my own initial feelings toward SOM were not warm and fuzzy. After we on the OpenDoc team decided to make the move to SOM, and I began reading about it and thinking about the task of converting our existing code base, I was heard to ask Kurt Piersol: “We’re all going to die, aren’t we?” Fortunately, I was wrong; and since then I’ve come to like and respect SOM.

Why Is SOM Necessary?

Object-based shared libraries are a holy grail of software engineering, since they turn code into black-box components that can be plugged together by programmers. Unfortunately, existing object models have been either too slow and too hard to use from existing code (e.g. Smalltalk), or insufficiently robust (e.g. C++.)

Fragile Base Classes

What do I mean by “insufficiently robust”? The technical term is fragile base-classes, and what it means is that changes to a base class - such as adding methods or instance variables - often break code that uses the base class, or makes subclasses of it, until that client code is recompiled.

In other words, if I update my JensTools C++ class library from version 1.0 to 1.1, and users install the new version, all their apps that use it may crash until they get new releases from the developers. Needless to say, this has impeded the use of object-based shared libraries.

There are two ways around this. The first is to abandon key features of object-oriented programming like inheritance and polymorphism. This is what Microsoft’s Component Object Model (COM) does. What you’re left with is a system of procedural dispatch tables that I find quite reminiscent of the Component Manager. I’ve used the Component Manager extensively as part of developing AppleScript, and let me say that it is not my favorite shared library solution. (For a much more detailed look at how SOM and COM differ, read “SOM vs. COM” in the documentation folder on the CD.)

The better solution is to attack the problem head on and fix it, which is what researchers at IBM did in producing SOM. I won’t go into the gory details here, but by abstracting the way object instantiation and method dispatch work, they were able to produce an object model that is extremely robust and still efficient and fully object-oriented.

In other words, by basing my JensTools library on SOM (though it’s still implemented in C++) I am able to add new methods and/or change its internal implementation while retaining full binary compatibility: when users install the new version, their existing apps continue to work perfectly, while new clients can take advantage of the new features.

Language and Compiler Neutrality

A frequently-mentioned advantage of SOM is that it can be used with any programming language, once the appropriate interfaces and glue code are written. This is because the SOM kernel isn’t based on any single object model, and has robust enough support for almost any language (for instance, it supports metaclasses and name-based dispatching, features found in Smalltalk but not in C++.) C and C++ support currently exist, with Smalltalk in the works.

Language neutrality is also sometimes disparaged; some see it as nothing more than unnecessary support for exotic languages that no one uses. Setting aside the fact that many large businesses are using Smalltalk, and that it would be damn cool to be able to write OpenDoc parts in Dylan, what these critics don’t realize or admit is that different C++ compilers might as well be different languages when it comes to their runtime object model. Due to differences in vtable layout and parameter passing, objects created by one C++ compiler generally cannot be used by client code compiled by a different C++ compiler. On the Mac, cfront, Apple’s new Mr.C compiler, Symantec C++ and Metrowerks’ C++ are all mutually incompatible.

This incompatibility causes headaches even with COM. A frequent trick used by COM programs is to use a C++ vtable as a COM method table. By strange coincidence, this works just fine with the vtables laid out by the Microsoft C++ compiler. But it doesn’t work with most other C++ compilers, and users of those compilers are forced to lay out the method tables by hand, which turns out to be a lot more difficult than creating a SOM class (in fact, it’s a lot like the tables SOM builds internally and thankfully hides from you.)

Cross-Platform Support

Implementations of SOM currently exist for OS/2, Unix, Windows, and now the Macintosh (both 68k and native PowerPC, included on the OpenDoc CD.) Future targets include Netware, IBM’s Workplace, MVS and OS/400. IBM plans to license SOM to Component Integration Labs, so it will be available for other vendors to license.

Using SOM With C++

This adds up to a pretty compelling case for using SOM. There’s nothing else available that supports real object-oriented programming, with strong binary compatibility, language and compiler independence, that runs on all major operating systems. Choosing it for OpenDoc was a no-brainer once we’d analyzed the alternatives.

Unfortunately you do give up some things when you use SOM from C++. SOM is not tied to the C++ object model, and it doesn’t support some fancier C++ features like templates and operator overloading (although it does do things C++ doesn’t, like metaclasses and name-based dispatching.) SOM classes aren’t the same as C++ classes; this isn’t apparent on the client side since you call methods of a SOM object exactly as you would a C++ object, but a SOM class’ methods are implemented as procedural functions, which adds a certain amount of “syntactic vinegar” to your implementation (as my colleague Richard Rodseth puts it.)

Many of these drawbacks will be alleviated by direct-to-SOM C++ compilers. These are compilers with a native understanding of the SOM object model, which make creating a SOM class as simple as inheriting from SOMObject. Direct-to-SOM compilers are already available for OS/2 and Windows, and may be on the Mac soon.

Until then, there are tricks you can use if you want to do your work closer to normal C++. One that works well, and is used in the sample OpenDoc leaf part class that comes with PartMaker, is to create a normal C++ class with basically the same API as the SOM class you want to implement. Then the SOM class’ implementation simply instantiates a matching object of the C++ class, and each SOM method calls the corresponding C++ method. This incurs a little bit of extra overhead, but eases the transition to SOM for someone familiar with C++.

Cool Features

SOM supports features you don’t ordinarily get with C++. For instance, you can determine the class of an arbitrary SOM object at runtime, or check whether an object descends from a particular class or implements a particular method. You can examine all the methods defined by a particular class and send an arbitrary message to an object given a string representing the method name. You can even add new methods to a class at runtime. All this is possible because SOM supports metaclasses, a concept originating in Smalltalk which means that SOM classes are real objects.

Building A SOM Class

The full process of implementing a SOM class consists of:

• Write an IDL file: a SOM header that declares your class’ interface. The class will inherit from an existing SOM class (such as SOMObject, or ODPart for an OpenDoc part handler). In the interface you add any extra methods and instance variables that your part objects will need.

IDL stands for Interface Definition Language, a simple syntax for defining classes. It’s part of the industry-standard CORBA architecture. Fortunately, IDL looks very much like a C++ class definition, with a few extensions.

• Crank your IDL file through the SOM compiler. This translates your part’s definition from the abstract IDL syntax into a C or C++ API, plus the appropriate magic glue for the SOM runtime. The output is several binding files that you use to build your part with C or C++.

• Fill out the implementation. One of the binding files generated is a .c or .cpp file that contains a blank C or C++ implementation of your part: the method functions are all there but their bodies are empty. You fill in the bodies with the actual code for each method.

• Compile and link the implementation files. The implementation binding file and any other source files you create are linked against the SOM library, and the libraries of any other SOM classes you use or inherit from, to produce a shared library that implements your class. You can use any compiler that knows how to build CFM shared libraries, such as scpp or CodeWarrior PPC.

• Iterate. If you fix bugs or make other changes that just modify existing class methods, or non-class code, all you need to do is recompile and relink. If you need to change the class structure by adding methods or instance variables, you’ll need to run the SOM compiler again. The (blank) new methods will be appended to your implementation file without disturbing the existing C/C++ code.

Networked Objects

SOM has an extension called DSOM that supports distributed objects. It allows SOM objects on different machines on a network (or in separate address spaces on one machine) to talk to each other as though they were all running in the same process. DSOM is pretty transparent to your code; you just have to avoid pitfalls like trying to send a remote object a raw pointer to data.

DSOM already runs on OS/2 and will be ported to the Mac OS; we plan to support it in the second release of OpenDoc to allow distributed parts, documents and other services.

On a broader scale yet, DSOM is an implementation of CORBA, an industry standard for distributed objects. This means that DSOM clients can interact with non-SOM distributed applications from vendors like DEC and H/P, running on workstations or mainframes. This gives SOM-based systems like OpenDoc a well defined way to connect to large corporate databases, which may or may not excite you but makes IS managers sit up and drool.

Conclusion

SOM is one of those things where you have to look at the big picture. Yes, it’s a bit of a pain at the micro-level of individual lines of code. But alternatives like COM, which may seem simpler at first, turn out to be more complicated when used with some compilers, and too limited to support true object-oriented programming. And SOM becomes extremely cool at the larger scale of reusable and robust shared class libraries, and positively mind-bending with its prospects of distributed objects and Net-spanning applications.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.