Jump to content

Introduction to SOM: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Introduction to SOM ([http://en.wikipedia.org/wiki/System_Object_Model System Object Model])
''by [[Prokushev]]''


by [[Prokushev]]
The '''System Object Model''' (SOM) is a language neutral object model. The main advantage of SOM is the possibility to implement classes in any language which supports DLL creation or usage. The only predefined thing for such a model is the interface, as described in terms of [[the SOM Interface Definition Language]], which can be translated to a corresponding language binding. Classes are represented in binary form. In language-specific object models, classes exist only virtually until compilation. For example, such a language could be C++, Delphi, Pascal or others. Actually, inheritance is implemented during runtime, like in true object-oriented languages like Smalltalk. Instances of classes are represented by object. Actually, objects of the same class share the same code. Code can be stored either in a DLL or in an EXE. Most usable is a DLL that can contain one or more classes. A DLL, in terms of SOM, named as class library. Most SOM functionality (except implementation of core logic) is implemented with a class library.


System Object Model (SOM, SOMObjects) is a language neutral object model. The main advantage of SOM is the possibility to implement classes in any language which supports DLL creation or usage. The only predefined thing for such a model is the Interface. Interface, as described in terms of [[Interface Definition Language]], which can be translated to a corresponding language binding. Classes are represented in binary form. In language-specific object models, classes exist only virtually until compilation. For example, such a language could be C++, Delphi, Pascal or others. Actually, inheritance is implemented during runtime, like in true object-oriented languages like SmallTalk. Instance of class represented by object. Actually, objects of the same class share the same code. Code can be stored either in a DLL or in an EXE. Most usable is a DLL. A DLL can contain one or more classes. A DLL, in terms of SOM, named as classes library. Most SOM functionality (except implementation of core logic) is implemented with a class library.
By default, OS/2 is shipped with a lot of general class libraries. Some of them are used every day and every minute, others not so often. Later we will briefly look at all of them.
 
By default, eComStation shipped a lot of general class libraries. Some of them used every day and every minute, others not so often. Later we will briefly look at all of them. Class libraries include:


Class libraries include:
* [[SOM Kernel]]
* [[SOM Kernel]]
* [[Interface Repository Framework]]
* [[Interface Repository Framework]]
* [[Metaclass Framework]]
*Metaclass Framework
* [[Event managment Framework]]
*Event Management Framework
* [[Distributed SOM]]
* [[SOM_DSOM#DSOM.2FCORBA_Framework|Distributed SOM]]
* [[Sockets classes]]
* [[SOM_DSOM#Sockets_interface|Sockets classes]]
* [[Replication Framework]]
* [[SOM_DSOM#Replication_Framework|Replication Framework]]
* [[Presistent Framework]]
* [[SOM_DSOM#Persistence_Framework|Persistent Framework]]
* [[Emitter Framework]]
* [[Emitter Framework]]
* [[Collection Classes]]
* [[SOM_DSOM#Collection_classes|Collection Classes]]
* [[Workplace Shell Classes/XWorkplace Classes]]
* Workplace Shell Classes/XWorkplace Classes (XWP not present in IBM's OS/2)
* [[Multimedia Classes/CWMM Classes]]
* Multimedia Classes/CWMM Classes (not present in IBM's OS/2)
 
The most notable classes (from a user's point of view) are the Workplace Shell Classes. Desktop objects are SOM at work. Every day users use SOM objects and most of them like it.
The most notable classes (from a user's point of view) are the Workplace Shell Classes. Desktop objects are SOM at work. Every day users use SOM objects and most of them like it.


SOM objects can be manipulated easily. Using the power of [[Object REXX]], SOM users and programmers can do fantastic things without any problems. WPS can be easely customized and manipulated with [[Object REXX]].
SOM objects can be manipulated easily. Using the power of [[Object REXX]], SOM users and programmers can do fantastic things without any problems. WPS can be easily customised and manipulated with Object REXX.


Another powerfull set of classes is [[OpenDoc Classes]]. Not part of eComStation system, they allow one to have higly integrated and user-friendly applications. If programmers will support OpenDoc then we can have lot of good application (sick! No application term in OpenDoc word!). No monsters like Open Office or Lotus Smart Suite. No applications like GIMP. Only components which allows one to build documents with very-very impressive content by easy operations. It is possible. It is the future of OS/2 and eComStation. We can make our word better. So, in future, we'll try to review [[OpenDoc classes]] closely.
Another powerful set of classes are the OpenDoc Classes. They allow one to have highly integrated and user-friendly applications. If programmers would support OpenDoc then we could have lots of good applications (sic - no "application" term in OpenDoc words!). Neither monsters like OpenOffice or Lotus SmartSuite, nor applications like GIMP any more. Only components which allow one to build documents with very-very impressive content by easy operations. So, in the future, we'll try to review OpenDoc classes closely.


Don't forget about DSOM classes - implementation of CORBA specification. Not the latest, but we can move forward and extend DSOM classes to support most (or all) features of current CORBA specification. It is also possible. SOM is an open model. Most classes and methods can be easily extended or replaced.
Don't forget about [[SOM_DSOM#DSOM.2FCORBA_Framework|DSOM classes]] - an implementation of CORBA specification. Not the latest, but we can move forward and extend DSOM classes to support most (or all) features of current CORBA specification. It is also possible. SOM is an open model. Most classes and methods can be easily extended or replaced.


Don't forget about other object models, either. Most notable is [[XPCOM]]. Mozilla users use XPCOM every time. It's DOM support. XPCOM can be wrapped by SOM classes and reused by OS/2 programmers. It's another topic for future reviews.
Don't forget about other object models, either. Most notable is XPCOM. Mozilla users use XPCOM every time. It's supported by DOM. XPCOM can be wrapped by SOM classes and reused by OS/2 programmers. It's another topic for future reviews.


Remember Java. Java classes and objects can be accessed via SOM. Mixing portable and native solutions allows us to have fantastic things. Native interface and cross-platform background. And vise versa.
Remember Java. Java classes and objects can be accessed via SOM. Mixing portable and native solutions allows us to have fantastic things. Native interface and cross-platform background. And vice versa.


We can do all of it, we must do all of it. We must learn such things as SOM. Really, things not so hard as we think.
We can do all of this, we must do all of it. We must learn things such as SOM. Really, things are not as hard as we may think.


Lets create our first SOM class. It is easy.
Let's create our first SOM class. It is easy.
#Write the interface
#Create binding
#Write class implementation
#Use class
Nothing hard. All too easy...


* Step 1. Write interface
=== Requirements ===
* Step 2. Create binding
* [[SOM Compiler]]
* Step 3. Write class implementation
* Watcom C compiler 32-bit (wcc386)
* Step 4. Use class
 
Nothing hard. All too easy...


=== Write interface ===
=== Write interface ===
The class interface must be described using [[the SOM Interface Definition Language]] (IDL).
Some developers use only implementation language to describe class interface (sic). Such an approach is ugly and incorrect. Doing so, they close their classes to others (Note: one may derive the IDL file from the implementation but it's cumbersome. On the other hand using a Direct-To-SOM compiler does have/had advantages. Nowadays, with the death of VAC++ the best way indeed is to use just IDL so one of the other available compilers can be used). Use the SOM IDL and nothing else. It's clear. It's easy. It's useful.


The class interface must be described using [[Interface Definition Language]].
Let's create a file called "demo.idl" with the following text inside:
Some developers use only implementation language to describe class
<code>
interface (sick!). Such an approach is ugly and incorrect. Doing so, they
close their classes to other (Note: one may derive the IDL file from the implementation but it's cumbersome. On the other hand using a Direct-To-SOM compiler do has/had advantages. Nowadays with the death of VAC++ the best way is indeed to use only IDL so one of the available compilers can be used). Use [[Interface Definition Language]] and
nothing more. It's clear. It's easy. It's useful.
 
  #include <somcls.idl>
  #include <somcls.idl>
  // include base classes
  // include base classes
Line 62: Line 60:
   // Very-very useful method
   // Very-very useful method
  };
  };
 
</code>
Is it hard? No!
Is it hard? No!


=== Create bindings ===
=== Create bindings ===
In short, use [[SOM Compiler]]:
In short, use [[SOM Compiler]]:
  sc -s"h;ih;c" demo.idl
  sc -s"h;ih;c" demo.idl
Result:
Result:
  demo.h
  demo.h
  demo.ih
  demo.ih
  demo.c
  demo.c
Is it hard? No!
Is it hard? No!


=== Write class implementation ===
=== Write class implementation ===
Ok. We have demo.c. Let's play the game:
Ok. We have demo.c. Let's play the game:
 
<code>
  /*
  /*
   *  This file was generated by the SOM Compiler and Emitter Framework.
   *  This file was generated by the SOM Compiler and Emitter Framework.
Line 95: Line 87:
   
   
  #include "demo.ih"
  #include "demo.ih"
   
   
  /*
  /*
Line 108: Line 99:
     '''printf("Write %s\n",_get_DemoWord(somSelf, ev));'''
     '''printf("Write %s\n",_get_DemoWord(somSelf, ev));'''
  }
  }
 
</code>
Is it hard? No! Let's compile the demo (don't forget to check include paths):
Is it hard? No! Let's compile the demo (don't forget to check include paths):
  wcc386 demo.c
  wcc386 demo.c


=== Use class ===
=== Use class ===
Do we need code which we can't use? No! Let's use it!
Do we need code which we can't use? No! Let's use it!


Let's create a text file named "test.c" and include the following code:
<code>
  #include "demo.h"
  #include "demo.h"
   
   
Line 143: Line 134:
   return 0;
   return 0;
  }
  }
</code>
Was it hard? No!


Was it hard? No! Let's create demo:
Let's create demo:
 
wcc386 test.c
  wcc386 test.c
wlink file demo.obj file test.obj library somtk.lib name test.exe
  wlink file demo.obj file test.obj library somtk.lib name test.exe
Run it! All must be OK. It's easy.


Run it! All must be Ok. It's easy.
[[Category:SOM Articles]]

Latest revision as of 22:51, 20 June 2019

by Prokushev

The System Object Model (SOM) is a language neutral object model. The main advantage of SOM is the possibility to implement classes in any language which supports DLL creation or usage. The only predefined thing for such a model is the interface, as described in terms of the SOM Interface Definition Language, which can be translated to a corresponding language binding. Classes are represented in binary form. In language-specific object models, classes exist only virtually until compilation. For example, such a language could be C++, Delphi, Pascal or others. Actually, inheritance is implemented during runtime, like in true object-oriented languages like Smalltalk. Instances of classes are represented by object. Actually, objects of the same class share the same code. Code can be stored either in a DLL or in an EXE. Most usable is a DLL that can contain one or more classes. A DLL, in terms of SOM, named as class library. Most SOM functionality (except implementation of core logic) is implemented with a class library.

By default, OS/2 is shipped with a lot of general class libraries. Some of them are used every day and every minute, others not so often. Later we will briefly look at all of them.

Class libraries include:

The most notable classes (from a user's point of view) are the Workplace Shell Classes. Desktop objects are SOM at work. Every day users use SOM objects and most of them like it.

SOM objects can be manipulated easily. Using the power of Object REXX, SOM users and programmers can do fantastic things without any problems. WPS can be easily customised and manipulated with Object REXX.

Another powerful set of classes are the OpenDoc Classes. They allow one to have highly integrated and user-friendly applications. If programmers would support OpenDoc then we could have lots of good applications (sic - no "application" term in OpenDoc words!). Neither monsters like OpenOffice or Lotus SmartSuite, nor applications like GIMP any more. Only components which allow one to build documents with very-very impressive content by easy operations. So, in the future, we'll try to review OpenDoc classes closely.

Don't forget about DSOM classes - an implementation of CORBA specification. Not the latest, but we can move forward and extend DSOM classes to support most (or all) features of current CORBA specification. It is also possible. SOM is an open model. Most classes and methods can be easily extended or replaced.

Don't forget about other object models, either. Most notable is XPCOM. Mozilla users use XPCOM every time. It's supported by DOM. XPCOM can be wrapped by SOM classes and reused by OS/2 programmers. It's another topic for future reviews.

Remember Java. Java classes and objects can be accessed via SOM. Mixing portable and native solutions allows us to have fantastic things. Native interface and cross-platform background. And vice versa.

We can do all of this, we must do all of it. We must learn things such as SOM. Really, things are not as hard as we may think.

Let's create our first SOM class. It is easy.

  1. Write the interface
  2. Create binding
  3. Write class implementation
  4. Use class

Nothing hard. All too easy...

Requirements

Write interface

The class interface must be described using the SOM Interface Definition Language (IDL). Some developers use only implementation language to describe class interface (sic). Such an approach is ugly and incorrect. Doing so, they close their classes to others (Note: one may derive the IDL file from the implementation but it's cumbersome. On the other hand using a Direct-To-SOM compiler does have/had advantages. Nowadays, with the death of VAC++ the best way indeed is to use just IDL so one of the other available compilers can be used). Use the SOM IDL and nothing else. It's clear. It's easy. It's useful.

Let's create a file called "demo.idl" with the following text inside:

#include <somcls.idl>
// include base classes

interface Demo : SOMObject
// Class Demo with parent SOMObject
{
 attribute string DemoWord;
 // Very-very useful data
 void sayDemoWord();
 // Very-very useful method
};

Is it hard? No!

Create bindings

In short, use SOM Compiler:

sc -s"h;ih;c" demo.idl

Result:

demo.h
demo.ih
demo.c

Is it hard? No!

Write class implementation

Ok. We have demo.c. Let's play the game:

/*
 *  This file was generated by the SOM Compiler and Emitter Framework.
 *  Generated using template emitter:
 *      SOM Emitter emitctm: 2.23.1.9
 */

#ifndef SOM_Module_demo_Source
#define SOM_Module_demo_Source
#endif
#define Demo_Class_Source

#include "demo.ih"

/*
 * Very-very useful method
 */

SOM_Scope void  SOMLINK sayDemoWord(Demo *somSelf, Environment *ev)
{
    DemoData *somThis = DemoGetData(somSelf);
    DemoMethodDebug("Demo","sayDemoWord");

    printf("Write %s\n",_get_DemoWord(somSelf, ev));
}

Is it hard? No! Let's compile the demo (don't forget to check include paths):

wcc386 demo.c

Use class

Do we need code which we can't use? No! Let's use it!

Let's create a text file named "test.c" and include the following code:

#include "demo.h"

int main(int argc, char *argv[])
{
  // Get environment info
  Environment *ev = somGetGlobalEnvironment();

  // Create demo1 and demo2 objects
  Demo *demo1 = DemoNew();
  Demo *demo2 = DemoNew();

  // Set DemoWord attribute of objects
  Demo__set_DemoWord(demo1, ev, "123");
  Demo__set_DemoWord(demo2, ev, "321");

  // Call sayDemoWord method of objects
  Demo_sayDemoWord(demo1, ev);
  Demo_sayDemoWord(demo2, ev);

  // Destroy objects
  _somFree(demo1);
  _somFree(demo2);

  // Finish
  return 0;
}

Was it hard? No!

Let's create demo:

wcc386 test.c
wlink file demo.obj file test.obj library somtk.lib name test.exe

Run it! All must be OK. It's easy.