Concept As A Generalization of Class and Principles of The Concept-Oriented Programming
Concept As A Generalization of Class and Principles of The Concept-Oriented Programming
Concept As A Generalization of Class and Principles of The Concept-Oriented Programming
net/publication/228529720
CITATIONS READS
20 238
1 author:
Alexandr Savinov
Bosch
66 PUBLICATIONS 478 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Alexandr Savinov on 15 May 2014.
Abstract
In the paper we describe a new construct which is referred
to as concept and a new concept-oriented approach to program-
ming. Concept generalizes conventional classes and consists of
two parts: an objects class and a reference class. Each concept
has a parent concept specified via inclusion relation. Instances
of reference class are passed by value and are intended to rep-
resent instances of child object classes. The main role of con-
cepts consists in indirecting object representation and access. In
concept-oriented programming it is assumed that a system con-
sists of (i) conventional target business methods (BMs), and (ii)
hidden representation and access (RA) methods. If conventional
classes are used to describe only BMs then concepts allow the
programmer to describe both types of functionality including its
hidden intermediate functions which are automatically executed
when objects are being accessed.
1 Introduction
1.1 Object Representation and Access
Let us consider a conventional method call: myRef.myMethod(). In
OOP it is assumed that a reference stores a target object identifier. It
is allocated and managed by routines which are not directly controlled
by the programmer. For example, memory handles are allocated by
the operating system and Java references are provided by the runtime
c
°2005 by A. Savinov
292
Concept as a Generalization of Class and . . .
293
A. Savinov
294
Concept as a Generalization of Class and . . .
295
A. Savinov
296
Concept as a Generalization of Class and . . .
297
A. Savinov
298
Concept as a Generalization of Class and . . .
1.4 Concept
299
A. Savinov
to that between real numbers and complex numbers. Class reflects only
an explicit (real) side of software system while concept is able to de-
scribe both sides by combining in one construct one object class and
one reference class. Reference class of concept describes invisible hid-
den functionality of a software system like imaginable part of complex
numbers. In the same way as complex numbers are much more ex-
pressive and natural for mathematical tasks, concept is much more
expressive and natural for computer programming.
300
Concept as a Generalization of Class and . . .
301
A. Savinov
00 concept Country
01 class { String countryDescription; }
02 reference { String cityName; }
This concept means that there can be many country objects each
having some description. A country then defines its own internal coor-
dinate or address system in reference class. According to this address
system any object within one country is identified via some unique city
name. Note that here we do not know how countries themselves are
identified because concepts define only their internal coordinate system
for which they are responsible.
Another example is where we define our own memory manager
where objects of any type can be stored. Concepts allow us to de-
fine such a storage at high level as an abstract space with its own name
and then take responsibility for everything that happens inside this
space. In particular, we can define characteristics of the space itself
in object class and its address format in reference class. The current
number of internal objects is kept in a field of the concept object class.
Internal objects themselves are identified by unique integers:
00 concept MemoryManager
01 class { int objectCount; }
02 reference { int objectId; }
We may have many memory managers and then many objects of
this concept will be created. Each such memory manager may create
many references each of them representing some internal object. Note
again that references are not objects because they are passed by value
and hence do not have a position in space (their own reference). In
contrast, objects have a position in space which is represented by some
reference.
Using concepts we can define the format of objects and format of
references that are intended to represent objects. Then the question
is how do we determine what references represent what objects? For
example, what references are used to represent country objects and
what references are used to represent memory manager objects in the
previous examples?
302
Concept as a Generalization of Class and . . .
00 concept CountryCode
01 class { int countryCount; }
02 reference { String countryCode; }
03 concept Country in CountryCode;
303
A. Savinov
304
Concept as a Generalization of Class and . . .
After that all instances of this child target class will be represented
indirectly by means of its parent references (integer identifiers). Let us
consider the following code:
Here the method parameter has a class that is included into the
custom memory manager concept. Hence this parameter will be passed
by using integer values. If we need to call some method of this object
then this reference (integer value) has to be resolved into its own parent
reference. In our case the integer value has to be resolved into some
long integer which is a memory handle allocated by the root. The root
reference is then used to make a direct method invocation. After that
the access procedure returns.
An object (instance of this concept object class) where a reference
was created is referred to as context. Context and its references belong
to the same concept. We say that references exist in some context
and one context may create many references. The current context is
available in the program via keyword ’context’. For example, line 10
in Table 1 accesses a method defined in the object class of this concept
(line 3).
If an object class is static with no instances (with a single instance
known at compile time) then such a concept is also said to be static.
If a concept has no reference class defined then it is a normal class.
A typical object run-time structure is shown in Fig. 2. Dashed
boxes represent contexts (objects of concepts) while black boxes are
references within these contexts. The outer most dashed box is the
root context, i.e., an instance of the root concept (such as the system
default memory manager). The root context has several root references
which represent internal child contexts at different depth (not neces-
sarily direct children). In this example there are two child contexts
belonging to one concept MemoryManager. (In general case there are
305
A. Savinov
many child concepts each crating many instances.) Thus there exist
two memory managers each managing its own set of objects. For exam-
ple, the first memory manager allocated two integer references in order
to represent two internal objects. However, these internal objects have
their own internal objects and so on.
306
Concept as a Generalization of Class and . . .
3 A Sequence of Access
3.1 Reference Substitution and Resolution
The system root concept provides default format for object references
which are used to directly represent and access all objects in the pro-
gram. Here direct RA does not mean that the objects will be really
accessed instantly. Rather, by direct access we mean that the program-
mer is not able to influence this level of RA functionality. For example,
we say that Java references provide direct access because the program-
mer is unaware of the underlying RA mechanism which actually can
be rather complex. Even physical memory addresses do not provide
the ultimate direct access because they are processed at hardware level
and each access requires a number of hardware clock cycles. However,
in a program we can assume that such hardware addresses are used for
direct access because all the program objects are resolved into them.
One important use of concepts consists in indirecting object rep-
resentation and access in the program by describing custom format of
references and custom access procedures. Program objects are still rep-
resented by the root references however these root references are not
stored and passed anywhere in the program as representatives. Instead,
objects are represented by means of custom references which replace
the corresponding root references. Since concepts are organized into a
hierarchy, the reference substitution has a nested nature. This means
that a child reference replaces some parent reference which in turn re-
places its own parent reference and so on till the root which provides
direct access to the target object. For example, a street within a city
might define its own local notation in order to identify houses. How-
ever, in order for the basic access mechanism to work we need to map
these local identifiers into the parent city-level identification format.
Thus each street-level local identifier will replace some city-level parent
307
A. Savinov
00 concept A in Root
01 class { static Map map; }
02 reference {
03 int id;
04 void continue() {
05 Object o = context.map.get(id);
06 o.continue();
07 }
08 }
09 concept B in A
10 class { static Map map; }
11 reference {
12 String id;
13 void continue() {
14 A a = context.map.get(id);
15 a.continue();
16 }
17 }
308
Concept as a Generalization of Class and . . .
309
A. Savinov
310
Concept as a Generalization of Class and . . .
00 MyTargetClass in B {
01 void targetMethod() { ... }
02 }
03
04 void myMethod(MyTargetClass param) {
05 param.targetMethod();
06 }
Notice again that when we call the target method (line 5 above) we
do not know how this object is represented and how it will be accessed.
It is the task of compiler to find all the parent concept and use their
functionality to organize the resolution procedure. In our example the
target object is included into concept B and hence it will be represented
by a text string. When a method of this object is invoked the compiler
needs to resolve this text string into the corresponding root reference
and then make a direct method call. Thus the compiler applies contin-
uation method of reference B to the reference representing the target
object (start of resolution in Fig. 3). The continuation method (lines
13-16 in Table 2) has to decide how to resolve this reference (text
311
A. Savinov
312
Concept as a Generalization of Class and . . .
313
A. Savinov
01 concept A in Root
02 class {
03 Map map;
04 void continue() { // Incoming method
05 continue(); // Outgoing (reference) method
06 }
07 }
08 reference {
09 int id;
10 void continue() {
11 Object o = context.map.get(id);
314
Concept as a Generalization of Class and . . .
12 o.continue();
13 }
14 }
15
16 cconcept B in A
17 class {
18 Map map;
19 void continue() { // Incoming method
20 continue(); // Outgoing (reference) method
21 }
22 }
23 reference {
24 String id;
25 void continue() {
26 A a = context.map.get(id);
27 a.continue();
28 }
29 }
315
A. Savinov
316
Concept as a Generalization of Class and . . .
scope and call its business method specified in the source access request.
Note that the sequence hreference 3, double arrow, reference 5, double
arrow, reference 6i is the resolution process described in the previous
section, which uses reference continuation method.
317
A. Savinov
318
Concept as a Generalization of Class and . . .
• reference initialization/clean up
319
A. Savinov
and clean up procedures do not have their own conventional names be-
cause this mechanism is not part of OOP, which provides RA function-
ality as a default mechanism. In the concept-oriented programming
both types of life-cycle management methods are equally important:
object creation/deletion and reference creation/deletion. In this situa-
tion dual methods are precisely what we need to implement this mech-
anism. Namely, each object class has methods create and delete
which are responsible for construction and destruction (initialization
and cleaning up). On the other hand, each reference class has the
same pair of methods (line 6, 22 for creation and 11, 27 for deletion
in Table 4) that are responsible for reference allocation and deletion.
The reference creation method is applied to a new (empty) instance of
reference class. After return this reference has to contain some correct
value identifying the child object for which it has been created.
Object creation and deletion follow the standard sequence of access
described in the previous section (Fig. 4). An example of reference
creation and deletion is shown in Table 4 (object creation is a con-
structor which simply initializes object fields). Just like the method
of continuation, creation and deletion methods take no parameters
and return no values. Assume that the MyTargetClass is included
into concept B and we create its instance as follows: MyTargetClass
target.create(). This statement is equivalent to the conventional
MyTargetClass target = new MyTargetClass(). Variable target
will contain a reference of parent concept B, i.e., a string identifier as
last segment. In order to initialize this reference the compiler will ap-
ply creation method of B (line 22). This method will generate a unique
string in order to identify new object in the current context (line 23).
Then it allocates a parent reference and calls the same method of cre-
ation to initialize this new empty reference (line 24). Finally the cre-
ation method remembers an association between this id and the parent
reference within the current context (line 25). This information can be
then used whenever this object needs to be accessed, for example, from
reference continuation method.
Line 24 is a reference creation method which is applied to empty
reference of concept A. It is implemented in the same way. First, it
320
Concept as a Generalization of Class and . . .
01 concept A in Root
02 class { static Map map; }
321
A. Savinov
03 reference {
04 int id;
05 void continue() { ... }
06 void create() {
07 id = context.getUniqueInteger();
08 Object o.create();
09 context.map.add(id, o);
10 }
11 void delete() {
12 Object o = context.map.get(id);
13 Object o.delete();
14 context.map.remove(id);
15 }
16 }
17 concept B in A
18 class { static Map map; }
19 reference {
20 String id;
21 void continue() { ... }
22 void create() {
23 id = context.getUniqueString();
24 A a.create();
25 context.map.add(id, a);
26 }
27 void delete() {
28 A a = context.map.get(id);
29 A a.delete();
30 context.map.remove(id);
31 }
32 }
322
Concept as a Generalization of Class and . . .
4 Uses of Concepts
4.1 Concept as a Generalized Class
Concept as a programming construct is a pair of one object class and
one reference class with special responsibilities described in the previ-
ous sections. In such a form it is a rather general instrument that has
many possible uses. In other words, concept can be applied in very
different forms in very different programming languages depending on
the goals. One possible application of concepts is interpreting them as
a generalized class. The idea is that the conventional object-oriented
programming languages can be then used as usual except that concepts
are used instead of classes. Concept inclusion is interpreted as a gener-
alized inheritance. Notice that if all concepts have only an object class
with empty reference class then we get the conventional object-oriented
case.
One important new property of the concept-oriented approach is
that each intermediate object in the hierarchy has its own reference
and life-cycle. In contrast, in OOP an object has always only one
reference independent of the number of its base objects. For example,
if class Circle inherits class Figure then in OOP all instances of class
Circle will have a reference which is also valid for its base object
of class Figure. In COP in general case it is not so. For example,
if concept Figure is included into concept Panel then all panels will
have their own unique references which are independent of references
allocated for figures. For each panel identified by some reference there
can be many figures with their own references allocated by its parent
panel. Within one concrete panel, figure objects are identified by their
short (local) references while outside in global scope figures need to
be identified by their long references consisting of two segments. In
larger scope we might need even more segments. For example, if panels
are included into windows then each figure reference consists of three
segments starting from window reference.
Internal objects have also their own independent life-cycle. We can
create and delete internal objects independent of their parent objects.
In OOP it is not so, and creating/deleting an object means creat-
323
A. Savinov
ing/deleting all instances starting from the root class and ending with
the last extension. Independent life-cycle is maintained by means of
dual creation and deletion methods. If a concept is being developed to
maintain its internal coordinate system then it should define the cor-
responding methods for reference creation and deletion that will serve
its child objects. Then its child objects will have references allocated
by the parent which will be also responsible for their resolution via
reference continuation method.
In the concept-oriented programming the role of concepts changes
significantly with respect to the role of classes. The main role of base
classes is object and functionality reuse. This means that base classes
are developed as pieces of generic functionality that can be then in-
herited and extended from child classes. The main role of concept in
COP consists in implementing a scope or space border with associated
functionality. Then any object that is created within this concept in-
herits this behaviour and can use it at run time. Objects are created
and function within a hierarchical space which determines many their
properties. In OOP it is done statically at compile time while in COP
this inheritance of behaviour and influence of context is performed dy-
namically at run time. As a scope or space border any concept has
to behave like an intermediate environment rather than an end point
in OOP. The main goal of such an environment consists in processing
incoming and outgoing access requests (method calls). For example,
a concept might accept an incoming request from outside in its ob-
ject method and after some processing continue its execution in a child
object (delegation):
00 concept Intermediate
01 class {
02 int total=0;
03 int requestCount=0;
04 void someMethod(int amount) {
05 total += amount;
06 requestCount++;
07 continue();
08 requestCount--;
324
Concept as a Generalization of Class and . . .
09 }
10 }
11 reference { ... }
Here we count the number of method calls which are currently be-
ing processed in variable requestCount (line 3) and also sum up all
the method parameters in variable total (line 2). Both variables are
stored in the current context (object class) so we always know how
many internal objects are being currently accessed via this method
(door in the border). Additionally we can determine the sum of all
parameters passed to this method. Line 7 is where we pass this re-
quest to the internal object for additional processing that is specific
to the extension. Here we clearly see that this method implements an
intermediate functionality that is however activated automatically.
325
A. Savinov
static concepts where object class has only static members and hence
does not produce run-time instances. In this case each namespace
can be declared as one reference class with static members belonging
to object class and non-static members belonging to reference class.
For example, in Table 5 we declare namespace Persistent (line 0).
Its static fields (lines 1) belong to object class while all other (non-
static) members belong to reference class. Any target object with the
class included in Persistent namespace will be identified by a unique
integer value which is supposed to correspond to this object primary
key in a database. Continuation method of this namespace (line 4) is
a reference method. Its task consists in transforming this primary key
into the target object root reference. It has to load the target object
from the database before it can be accessed (line 4) and freeing this
object after the access has been finished (line 6).
326
Concept as a Generalization of Class and . . .
deal of the program functionality however its functions are used implic-
itly. A target class may change its behaviour depending on its parent
namespace.
327
A. Savinov
328
Concept as a Generalization of Class and . . .
5 Related Work
An approach described in this paper is being developed within a new
paradigm which covers several branches in computer science including
programming, data modelling [1,2,3] and system design. The concept-
oriented paradigm is based on several general principles that distinguish
it from the currently existing theories and approaches. In the context of
programming the most important concept-oriented assumption is that
system functionality is concentrated on space borders. In contrast,
in object-oriented paradigm it is assumed that most of functionality is
concentrated in objects themselves. Concept as the main programming
construct allows the programmer to describe effectively not only what
happens in objects but simultaneously what happens when they are
being accessed.
The concept-oriented programming can be considered a continua-
tion of a very general and deep principle of Separation of Concerns
formulated by Dijkstra [4]. The main idea of this principle is that any
problem or system functionality can be viewed from different points
of views or concerns. One specific feature of our approach is that we
distinguish two main concerns any program consists of: BMs and RA.
Currently there exist different techniques for separating business meth-
ods from representation and access functionality but they can be broken
into two main categories: methods based on dedicated middleware and
approaches based on programming languages.
The idea of middleware-based approaches consists in creating spe-
cial software and hardware environments where a conventional program
will run. Such an environment offers a number of functions that are
intended to support custom RA functionality. This special environ-
ment can exist and be accessible to running programs in very different
forms, for example, as part of an operating system, an object container,
a service, a dynamically or statically linked library etc. However, the
main property of this approach is that the programming language re-
mains the same while the support is provided by developers of the
329
A. Savinov
330
Concept as a Generalization of Class and . . .
the system.
One wide-spread technique to automating intermediate RA func-
tions consists in using static or dynamic proxies [10]. Proxy is a special
class that emulates an interface of the corresponding target class but
inserts some intermediate functionality. These intermediate functions
of the proxy class are called before target methods and hence they ef-
fectively intercept all target object method invocations. The trick here
consists in using proxy class instead of the target class. Thus it is not a
real interception but rather a normal sequence of method calls. In other
words, in the source context a reference to the proxy instance is created
and hence its methods are called when it is used. Then it is the task
of the proxy to decide what to do if some its method has been called.
Normally, after some processing the corresponding target method is
called. One disadvantage of this approach is that it requires significant
manual support and is not very general. It is more a special technique
or programming pattern rather than a programming paradigm. Here
are other disadvantages of this approach:
• For each target class we need to develop its own proxy while in
many cases proxy functions are rather general and can be used
by many target classes.
331
A. Savinov
6 Conclusions
In the paper we introduced a new programming construct called con-
cept. Concept is defined as a pair of one object class and one refer-
ence class having their own fields and methods (possibly with the same
name). Concepts are organized into a hierarchy using inclusion relation
with the main purpose to specify how objects have to be represented
and accessed. The main idea is that an object is represented by its par-
ent reference which replaces a system default reference. An approach
to programming based on this new construct is called concept-oriented
programming. This approach assumes that a system consists of two
332
Concept as a Generalization of Class and . . .
References
[1] Savinov, A. Principles of the Concept-Oriented Database Model,
Institute of Mathematics and Informatics, Academy of Sciences of
Moldova, Technical Report, 54pp., November 2004.
333
A. Savinov
[8] Kiczales, G., Rivieres, J., Bobrow, D.G. The Art of the Metaobject
Protocol. MIT Press, Cambridge, 1991.
[9] Kiczales, G., Ashley, J.M., Rodriguez, L., Vahdat, A., Bobrow,
D.G. Metaobject protocols: Why we want them and what else
they can do. In: Paepcke, A. (ed.) Object-Oriented Programming:
The CLOS Perspective, 101–118, The MIT Press, Cambridge, MA,
1993.
334
View publication stats
[16] Kiczales, G., Lamping, J., Mendhekar, A., Maeda, C., Lopes,
C., Loingtier, J.-M. and Irwin, J. Aspect-Oriented Programming,
Proc. ECOOP’97, LNCS 1241, 220–242, Jyvaskyla, Finalnd, 1997.
Alexandr Savinov, Received December 21, 2005
Institute of Mathematics and Informatics,
Academy of Sciences of Moldova
str. Academiei 5,
MD-2028 Chisinau, Moldova
E–mail: savinov@conceptoriented.com
Home page: http : //conceptoriented.com/savinov
335