<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>DeepRuby: Extending Ruby with Dual Deep Instantiation</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Bernd Neumayr</string-name>
          <email>bernd.neumayr@jku.at</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Christian Horner</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Christoph G. Schuetz</string-name>
          <email>christoph.schuetz@jku.at</email>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Michael Schrefl</string-name>
          <email>michael.schrefl@jku.at</email>
          <xref ref-type="aff" rid="aff3">3</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Business Informatics - Data &amp;, Knowledge Engineering, Johannes Kepler University Linz</institution>
          ,
          <addr-line>Linz</addr-line>
          ,
          <country country="AT">Austria</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Department of Business Informatics - Data &amp;, Knowledge Engineering, Johannes Kepler University Linz</institution>
          ,
          <addr-line>Linz</addr-line>
          ,
          <country country="AT">Austria</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Department of Business Informatics - Data &amp;, Knowledge Engineering, Johannes Kepler University Linz</institution>
          ,
          <addr-line>Linz</addr-line>
          ,
          <country country="AT">Austria</country>
        </aff>
        <aff id="aff3">
          <label>3</label>
          <institution>Department of Business Informatics - Data &amp;, Knowledge Engineering, Johannes Kepler University Linz</institution>
          ,
          <addr-line>Linz</addr-line>
          ,
          <country country="AT">Austria</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>-Clabjects, the central construct of multi-level modeling, overcome the strict separation of class and object in conceptual modeling. Ruby, a dynamic object-oriented programming language, similarly treats classes as objects and thus appears as a natural candidate for implementing clabject-based modeling constructs. In this paper we introduce DeepRuby, a Ruby implementation of the core constructs of Dual Deep Instantiation: clabject hierarchies and attributes with separate source potency and target potency. DeepRuby represents clabjects at two layers: the clabject layer and the clabject facet layer. At the clabject facet layer, a clabject with maximum source potency i-1 and maximum target potency j-1 is represented by a matrix of i j clabject facets organized using Ruby's superclass and eigenclass constructs. Clabject facets can easily be extended with behavior implemented in custom methods. Index Terms-Object oriented programming, Metamodeling</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>I. INTRODUCTION</p>
      <p>Object-orientation is arguably the most important paradigm
in programming and conceptual modeling. Statically-typed
object-oriented programming languages, like Java, and
traditional conceptual modeling approaches, like E/R and UML,
come with a strict separation between class and object. The
clabject as central construct of multi-level modeling [10]
overcomes this separation and not only plays the roles of class and
object but also of metaclass, potentially at many classification
levels. Extending traditional modeling/programming languages
to supporting clabjects is difficult, due to this inherent
mismatch. Dynamically typed languages like Ruby overcome the
strict separation between object and class: classes are also
treated as objects and may be extended at runtime. Based on
this kinship, Ruby suggests itself as a suitable language for
implementing multilevel modeling constructs.</p>
      <p>Deep Instantiation [2] is one of the most prominent
approaches to multi-level modeling. A potency assigned to a
clabject or property indicates the number of instantiation
levels, i.e., the number of instantiation steps to reach the
ultimate instance of the clabject or property. For example,
clabject CarModel with potency 2 is instantiated by BMW Z4
with potency 1 which is in turn instantiated by Peter’s Car
with potency 0. Clabject CarModel defines a property engine
with potency 2 and target EngineModel which is instantiated
by BMW Z4 has engine EngineK5 and in turn by Peter’s Car
has engine Engine123; Engine123 is an instance of EngineK5
which is an instance of EngineModel. Clabject CarModel
further defines a property listPrice with target currency value
and potency 1 which is instantiated by BMW Z4 has list price
e 42,232.</p>
      <p>Dual Deep Instantiation [9] (DDI) allows to specify the
number of instantiation steps separately for the source and for
the target of a property. For example, clabject CarModel, as
source, introduces property owner with source potency 2 and
target Person with target potency 1. This property is ultimately
instantiated between instances of instances of CarModel as
source and instances of Person as target, for example by Peters
Car has owner Peter. Clabject CarModel further has a
selfdescribing property creator with source potency 0 and target
Person and target potency 1. This property is instantiated
between CarModel as source and an instance of Person as
target, for example by CarModel has creator Peter.</p>
      <p>In previous work, we formalized different variants of DDI
in deductive database languages, namely F-Logic [9] and
ConceptBase [11], but without support for implementing behavior.
In this paper we introduce DeepRuby, an implementation of
DDI in Ruby that supports the implementation of custom
methods. DeepRuby makes heavy use of Ruby’s dynamic
programming and metaprogramming facilities [12]. The
DeepRuby version presented in this paper only implements a subset
of DDI: it does neither support clabject generalization nor
multi-valued attributes. These simplifications allow to set the
focus on the following core idea of DeepRuby.</p>
      <p>DeepRuby implements DDI at two layers, the clabject
BasicObject</p>
      <p>#BasicObject</p>
      <p>Object
instance_
variables()
inspect2()</p>
      <p>Person
age()
age=()
initialize()</p>
      <p>#Mary
name()
name=()</p>
      <p>Module
attr_accessor()</p>
      <p>
        Class
#Object
#Person
counter()
incCounter()
#Woman
layer and the clabject facet layer. DeepRuby’s clabject facet
layer makes explicit each of the otherwise implicit facets
of a DDI clabject by a flat Ruby object. For example,
clabject facet CarModelˆ(
        <xref ref-type="bibr" rid="ref1 ref2">2,1</xref>
        ) with property owner=Person
represents the instance-instance-type of CarModel. Clabject
facet CarModelˆ(
        <xref ref-type="bibr" rid="ref1">0,1</xref>
        ) with property creator=Person represents
the self-type of CarModel. CarModelˆ(0,0) with property
creator=Peter represents the self-value of CarModel. Clabject
facet CarModelˆ(
        <xref ref-type="bibr" rid="ref2 ref2">2,2</xref>
        ) with property engine=EngineModel
represents the instance-instance-metatype of CarModel. Clabject
facet CarModelˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        ) with property listPrice=CurrencyValue
represents the instance-type of CarModel.
      </p>
      <p>In the remainder of the paper, we give, in Sect. II, an
introduction to Ruby’s object model. In Sect. III, we introduce
a more intricate example DDI model and its representation
in DeepRuby. We also explain the clabject naming scheme
typically used with DDI for clabjects with more than two
instantiation levels. Sect. IV explains the clabject facet layer.
Sect. V exemplifies the extension of clabject facets with
custom methods. Sect. VI gives an overview of related work.
Sect. VII concludes the paper with ongoing and future work
regarding the implementation of advanced constructs of DDI [9]
and Dual Deep Modeling [11].</p>
      <p>II. BACKGROUND: RUBY’S OBJECT MODEL</p>
      <p>As a background for forthcoming sections this section
explains some relevant aspects of Ruby’s object model along
a small but intricate example (see Fig. 1).</p>
      <p>Ruby’s modules provide a namespacing mechanism for
constants, such as class names. Class Person (see line 1:2,
that is line 2 in the listing in Fig. 1) is created within
module Social and can be accessed outside the module by
qualified name Social::Person (line 1:32). Note: method
puts writes a string representation of the given object to an
IO stream – for illustration, the actual output of the Ruby
program is given in the program as a comment (e.g., # =&gt;
(Social::Person)).</p>
      <p>Member attributes of a Ruby class are defined as getter
and setter methods that access instance variables. Instance
variables are created when set by a method. To avoid the need
to write getters and setters by hand, class Module provides
a method attr_accessor that creates getter and setter
methods for an attribute of a given name. For example, in line
1:3, class Person (an instance of Class which inherits from
class Module) calls attr_accessor for symbol :age to
create setter method age= and getter method age in class
Person to write and read instance variables @age (names
of instance variables are marked by prefix ‘@’) of instances of
class Person, such as Mary (see line 1:16 and line 1:17).</p>
      <p>In Ruby, classes are treated as objects and can have instance
variables themselves, called class instance variables. Classes
are instances of class Class and also may have an eigenclass
(also referred to as singleton class). Methods defined with
a class’s eigenclass (also referred to as singleton methods</p>
      <p>Car2
categoryMgr0-0</p>
      <p>= MsBlack
engine2-2
= CarEngine
or class methods) can be used to access a class’s class
instance variables. The eigenclass of a class has as
superclass the eigenclass of the class’s superclass. For example,
Person’s eigenclass (labelled #Person in the graphical
representation) is opened by ‘class &lt;&lt; Person’ at line
1:8. Person’s eigenclass defines a getter method counter
(line 1:9) together with a method incCounter (line 1:10)
which is called (line 1:5) to increment the counter every
time a new object is created. Class Woman has superclass
Person (defined by ‘class Woman &lt; Person’ at line
1:14) and, thus, #Woman (the eigenclass of Woman) has
superclass #Person (the eigenclass of Person).</p>
      <p>Class instance variables really belong to the class (as an
object) and class methods are called in the context of a class
object. For example, when calling Woman.new to create a
new instance of class Woman the initializer defined with class
Person (line 1:4) is called, incCounter is called in the
context of class Woman setting instance variable @counter
of Woman to 1 (see comment in line 1:19) and not of Person
which remains undefined (see comment in line 1:18).</p>
      <p>Single objects may also have singleton classes with
singleton methods. For example, Mary’s singleton class (opened at
line 1:20 by class &lt;&lt; Mary and depicted as #Mary)
defines getter and setter methods for accessing instance variable
@name of Mary.</p>
      <p>Ruby allows to open existing classes to add additional
methods which then affect all direct and indirect instances of
the class. For example, class Object (opened at line 1:25) is
the direct or indirect superclass of all custom classes created
in Ruby programs and also the superclass of class Module
and Class. A method added to class Object can thus be
called from any Ruby object (with Ruby classes being also
Ruby objects). Method inspect2 (line 1:26) is defined with
class Object; when invoked on an object, it creates a string
consisting of the object’s name and its instance variables (see
lines 1:32–1:36).</p>
      <p>III. DUAL DEEP INSTANTIATION IN RUBY – AN EXAMPLE</p>
      <p>In this section DeepRuby is explained along the example
depicted and implemented in Fig. 2. Ruby’s modules are used
as namespacing mechanism. The clabjects of a DDI model
are created within such a module/namespace. For example,
module SalesMgmt (line 2:1) serves as namespace for a DDI
model with depth 3 (line 2:2), i.e., a model with maximum
source and target potencies of 3.</p>
      <p>Creating clabject hierarchies. A DDI model consists of one
or more clabject hierarchies. Every clabject hierarchy has one
root clabject. A root clabject has a fixed clabject potency
(specifying the number of instantiation levels beneath the root)
and typically has a name. For example, clabject Person (line
2:3) and clabject Product (line 2:11) are the root clabjects
in the SalesMgmt model and have a potency of 1 and 3,
respectively.</p>
      <p>Clabjects are instantiated by sending message new. The
new clabject is in the same module as its class and has a
potency 1 lower than its class. For example, clabject Person
with potency 1 is instantiated by MsBlack (line 2:4) and by
Peter (line 2:5), which get potency 0. Clabject Product
with potency 3 is instantiated by Bike (line 2:14) and by
Car (line 2:19) which get potency 2.</p>
      <p>Naming clabjects. The names of clabjects in DDI models
(such as in Fig. 2) may seem counter-intuitive. For example,
one would typically consider a class named Car to be a
specialization (and not an instantiation) of class Product.
In the following we explain how to read such models and
sketch the rationale behind this naming scheme.</p>
      <p>It is sometimes argued that deep instantiation’s support for
concise modeling comes with the price of lack of
conceptual clarity [3]: one clabject may represent multiple domain
concepts which makes it more difficult to differentiate these
different domain concepts. In order to make these different
domain concepts explicit, we proposed [9]–[11] to give
meaningful names to instantiation levels of a clabject and to produce
the name of an implicitly represented domain concept by
combining a clabject name with a level name.</p>
      <p>For example (see Fig. 2), clabject Product has
instantiation levels Category, Model, and Individual, representing
domain concepts Product Category, Product Model, and Product
Individual. Clabject Car is an instance of Product Category
and further represents domain concepts Car Model and Car
Individual (which are specializations of Product Model and
Product Individual). Clabject BMWZ4 is an instance of Car
Model and further represents domain concept BMWZ4
Individual (a specialization of Car Individual). Finally, Peters Car
is an instance of BMWZ4 Individual.</p>
      <p>Defining and instantiating attributes. Attributes are defined
with a source clabject, a name, a source potency, a target
potency, and a target clabject. For example, clabject Product
defines an attribute with name owner, source potency 3, target
potency 1, and target clabject Person (line 2:13).</p>
      <p>
        A clabject has many clabject facets, one for each
combination of source potency and target potency. In order to
set attribute engine at source potency 1 and target
potency 1 at clabject BMWZ4 to EngineK5, one first selects
the clabject facet (BMWZ4.ˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        )) to which one sends
engine=EngineK5 (line 2:23).
      </p>
      <p>Clabjects with potency 0 have no members, yet they may
define attributes with a target potency higher than 0, similar to
what can be accomplished in Ruby with singleton classes of
an object (e.g., attribute name defined with Mary’s singleton
class at line 21 in Fig. 1). For example, clabject Peter defines
an attribute spouse with source potency 0, target potency 1,
and target Person (line 2:6) and instantiates it with target
potency 0 and target MsBlack (line 2:7).</p>
      <p>Root clabjects with clabject potency 1 are akin to ‘normal’
classes in that they have individuals as members. They are
different from normal classes in that their attributes may have
a range defined at a higher classification level. For example,
Person (line 2:3) has individuals MsBlack (line 2:4) and
Peter (line 2:5) as members, yet it defines an attribute
favouriteItem (line 2:27) with target Product and
target potency 3, meaning that the range of favouriteItem
is given by the members of the members of the members of
clabject Product.</p>
      <p>Querying clabject hierarchies and attributes. The values
and (meta) types of a clabject’s attributes are queried by
sending the attribute name to the clabject facet which is
identified by the clabject together with source potency and
target potency. For example, sending attribute name engine
to PetersCar’s clabject facet with source potency 0 and
target potency 1 (line 2:32) returns the type of engine of
PetersCar, which is EngineK5, which is inherited from
BMWZ4.</p>
      <p>For getting or setting attributes with source potency 0 and
target potency 0 it is not necessary to specify the clabject facet.
If a message is sent to a clabject it dispatches it to its 0-0 facet.
For example, when sending attribute name favouriteItem
to Peter (line 2:30) it is dispatched to Peterˆ(0,0) and
retrieves Peter’s favourite item, which is his car.</p>
      <p>DeepRuby provides methods to navigate clabject hierarchies
to facilitate flexible querying of DDI models. For example,
line 2:34 retrieves the members of the members of Product,
these are BMWZ4 and Brompton.</p>
      <p>
        DeepRuby provides (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) generic query mechanisms (1a) to
retrieve attribute values and (meta) types including inherited
values and types (1b) to navigate clabject hierarchies and
retrieve a clabject’s members at a specific level and (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) takes
care of keeping DDI models consistent when defining and
setting attributes, with regard to: (2a) correct number of
instantiation steps at the source and the target, (2b) target
clabjects are compatible with targets at higher potencies, (2c)
a newly introduced target does not produce type conflicts at
lower potencies and at descending clabjects.
      </p>
      <p>IV. DEEPRUBY UNDER THE HOOD</p>
      <p>
        By freely combining source and target potencies, a clabject
c with maximum source potency m (given by the clabject’s
potency) and maximum target potency n (given by the DDI
model’s depth) has (m + 1) (n + 1) clabject facets. Every
such facet corresponds to a combination of source potency and
target potency. The basic idea of DeepRuby is to represent
every such clabject facet as a ’flat’ Ruby object (which in
the current approach is always a class) with instance variables
and methods. For example, clabject Car with potency 2 in a
model with depth 3 has 12 (3 4) clabject facets. The object
Carˆ(0-0) holds @catMgr=MsBlack and Carˆ(
        <xref ref-type="bibr" rid="ref2">2-2</xref>
        )
holds @engine=CarEngine as instance variable. The
relationships between clabject facets are represented using Ruby
constructs:
      </p>
    </sec>
    <sec id="sec-2">
      <title>The eigenclass of clabject facet ci;j is clabject facet ci;(j+1). For example, the eigenclass of class</title>
      <p>
        Carˆ(0,0) is clabject facet Carˆ(
        <xref ref-type="bibr" rid="ref1">0,1</xref>
        ).
      </p>
      <p>
        If clabject c is an instantiation of clabject d, then
every clabject facet ci;j has clabject facet d(i+1);j
as superclass. For example, Carˆ(0,0) has
superclass Productˆ(
        <xref ref-type="bibr" rid="ref1">1,0</xref>
        ) and Carˆ(
        <xref ref-type="bibr" rid="ref1">0,1</xref>
        ) has superclass
Productˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        ).
      </p>
      <p>
        Product^(
        <xref ref-type="bibr" rid="ref2">2,0</xref>
        )
      </p>
      <p>
        Product^(
        <xref ref-type="bibr" rid="ref1 ref2">2,1</xref>
        )
      </p>
      <p>
        Product^(
        <xref ref-type="bibr" rid="ref2 ref2">2,2</xref>
        )
1
Product^(
        <xref ref-type="bibr" rid="ref1">0,1</xref>
        )
      </p>
      <p>
        Product^(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        )
@catMgr = Person
catMgr();catMgr=()
A clabject is first represented as an instance of class
Clabject (line A:25 in the Appendix) with an array
levels which holds for each source potency a reference
to the respective instance of class ClabjectFacet (see
line A:210) with target potency 0, from there one can navigate
to other clabject facets along eigenclass relationships. Sending
message ˆ(i,j) to a clabject c returns clabject facet ci;j .
A clabject facet’s attribute clabject (line A:213) allows
to navigate back from clabject facet to clabject; for example,
from clabject facet Carˆ(
        <xref ref-type="bibr" rid="ref1 ref2">2,1</xref>
        ) to clabject Car.
      </p>
      <p>What is the role of superclass relationships in
DeepRuby?:</p>
    </sec>
    <sec id="sec-3">
      <title>Methods are inherited from superclass di+1;j to subclass</title>
      <p>
        ci;j (this comes for free, since this is what class
hierarchies are traditionally used for). For example, setter
method engine= defined at Carˆ(
        <xref ref-type="bibr" rid="ref1 ref2">2,1</xref>
        ) is inherited
by BMWZ4ˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        ) and in turn by PetersCarˆ(
        <xref ref-type="bibr" rid="ref1">0,1</xref>
        ).
Target clabjects of attributes (represented as instance
variables) are inherited from superclass ci+1;j to sublass
ci;j (this is implemented generically as part of
DeepRuby). For example, when sending message engine
to PetersCarˆ(
        <xref ref-type="bibr" rid="ref1">0,1</xref>
        ) one gets EngineK5, which is
inherited from BMWZ4ˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        ).
      </p>
      <p>What is the role of eigenclass relationships in
DeepRuby?:</p>
    </sec>
    <sec id="sec-4">
      <title>The eigenclass ci;j+1 of a clabject facet ci;j pro</title>
      <p>
        vides methods for accessing instance variables of
ci;j (this comes for free with the eigenclass
construct). For example, setter method catMgr=
defined in Productˆ(
        <xref ref-type="bibr" rid="ref1 ref2">1,2</xref>
        ) is called for setting
@catMgr=Person in Productˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        )
Target clabjects (represented as instance variables) at
instantiation_of
      </p>
      <p>
        PetersCar^(
        <xref ref-type="bibr" rid="ref1">0,1</xref>
        )
      </p>
      <p>
        PetersCar^(
        <xref ref-type="bibr" rid="ref2">0,2</xref>
        )
      </p>
      <p>
        PetersCar^(
        <xref ref-type="bibr" rid="ref3">0,3</xref>
        )
      </p>
      <p>
        DeepRuby
Clabject Facet Layer
ci;j+1 act as constraint for target clabjects at ci;j
(this is implemented generically as part of DeepRuby).
For example, target clabject engine=EngineK5 of
PetersCarˆ(
        <xref ref-type="bibr" rid="ref1">0,1</xref>
        ) (inherited from BMWZ4ˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        ))
acts as constraint when invoking setter method engine=
on PetersCarˆ(0,0).
      </p>
      <p>We have further been experimenting with two alternative
representation of the clabject facet matrix: In the first
alternative represenation, clabject facets with target potency 0 are
represented as simple objects and not as classes. This would
also be a reasonable design choice since these facets do not
act as classes, yet it makes the implementation a bit more
complex.</p>
      <p>
        In the second alternative representation, we introduce an
additional layer between DDI-clabject layer and clabject facet
layer in order to align DeepRuby with DeepTelos [6]. At this
intermediate layer, a DDI clabject is represented by multiple
simple clabjects. A simple clabject resembles an object, class,
metaclass, or metaˆn class in DeepTelos. Clabject facets with
the same difference between source potency and target potency
are collected into such a simple clabject. For example, clabject
facets Carˆ(0,0), Carˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        ), Carˆ(
        <xref ref-type="bibr" rid="ref2 ref2">2,2</xref>
        ) are collected
into a simple clabject Car 0 and clabject facets Carˆ(
        <xref ref-type="bibr" rid="ref1">1,0</xref>
        ),
Carˆ(
        <xref ref-type="bibr" rid="ref1 ref2">2,1</xref>
        ) are collected into a simple clabject Car 1, with
Car 0 having class Car 1 as its most-general instance. A
simple clabject combining facets where the target potency
is higher than the source potency (e.g., Productˆ(
        <xref ref-type="bibr" rid="ref1">0,1</xref>
        ),
Productˆ(
        <xref ref-type="bibr" rid="ref1 ref2">1,2</xref>
        ), Productˆ(
        <xref ref-type="bibr" rid="ref2 ref3">2,3</xref>
        )) cannot be directly
represented in DeepTelos.
      </p>
      <p>In this section we have explained the basic principles of
DeepRuby’s implementation and use of Ruby’s eigenclass
construct to implement Dual Deep Instantiation and have
sketched two alternative representations. The evaluation and
fine-tuning of these alternatives is subject to ongoing work.</p>
      <p>V. SIMPLE ATTRIBUTES AND CUSTOM METHODS IN</p>
      <p>DEEPRUBY</p>
      <p>Using classes/eigenclasses arranged in superclass
hierarchies for realizing the clabject facet matrix allows to use
standard Ruby constructs to implement simple attributes (attributes
with non-clabjects as range) and behavior (custom methods)
on top of the clabject facet matrix, and to specialize behavior
(i.e., overwrite methods, add additional methods) along the
clabject hierarchy.</p>
      <p>To demonstrate these features, the running example from
Fig. 2 is extended in Fig. 4 with clabject hierarchies
Currency with simple attributes for exchange rate (with
Euro as reference currency), isocode and value, and Country
with a local currency. Clabject Product is extended with a
listPrice and a method priceInCountry to convert
the list price to the local currency of the given country.</p>
      <p>
        First-level members of Currency receive getters and
setters for simple attributes exchRate and isocode
by invoking standard Ruby method attr_accessor
on the eigenclass of Currency.ˆ(
        <xref ref-type="bibr" rid="ref1">1,0</xref>
        ) (which is
Currency.ˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        )) (see line 4:4). Second-level
members of Currency get getter and setter for attribute
value by invoking attr_accessor on the eigenclass of
Currency.ˆ(
        <xref ref-type="bibr" rid="ref2">2,0</xref>
        ) (which is Currency.ˆ(
        <xref ref-type="bibr" rid="ref1 ref2">2,1</xref>
        )) (line
4:7). Currencies Pound, Euro, and Yen are created with
their isocode and exchange rate (lines 4:20–4:25). GBP38200
is an instantiation of Pound (and a second-level member of
Currency) with value 38200 (line 4:26).
      </p>
      <p>
        Second-level members of Currency have a method
for pretty printing (defined with the eigenclass of
Currency.ˆ(
        <xref ref-type="bibr" rid="ref2">2,0</xref>
        ) which is Currency.ˆ(
        <xref ref-type="bibr" rid="ref1 ref2">2,1</xref>
        )),
making use of value and isocode. In order to get the
isocode the method needs to first navigate from the clabject
facet (instance of ClabjectFacet) to the corresponding
clabject (instance of Clabject) along attribute clabject
and from there along attribute cclass to the corresponding
first-level member of Currency (line 4:9). Sending pretty
to GBP38200 results in ‘GBP 38200’ (line 4:27).
      </p>
      <p>Second-level members of Currency further have a
method toCurrency which takes a first-level member of
Currency as parameter (line 4:11). Sending toCurrency
with parameter Euro to GBP38200 produces a new
instantiation of Euro which is pretty printed as ‘EUR 42784.0’ (line
4:28).</p>
      <p>
        The eigenclass of Yen.ˆ(
        <xref ref-type="bibr" rid="ref1">1,0</xref>
        ) (which is
Yen.ˆ(
        <xref ref-type="bibr" rid="ref1 ref1">1,1</xref>
        )) overwrites method pretty inherited
from Currency.ˆ(
        <xref ref-type="bibr" rid="ref1 ref2">2,1</xref>
        )) to use unicode symbol U instead
of isocode JPY . The new instantiation of Yen created by
sending toCurrency with parameter Yen to GBP38200 is
pretty printed as ‘U 5556363.64’ (line 4:33).
      </p>
      <p>Clabjects UK and Japan instantiate Country and have
local currencies Pound and Yen, respectively. Asking for
the exchange rate of Japan’s local currency returns 0.0077
(line 4:39).</p>
      <p>Method priceInCountry (see line 4:42) of
secondlevel members of Product takes a country as parameter
and converts the listPrice of second-level instantiations
of Product to the country’s local currency, returning a new
instantiation of the given currency with the value being the
result of the conversion. Sending priceInCountry with
parameter Japan to BMWZ4 (see line 4:48) returns a new
clabject pretty-printed as ‘U 5556363.64’ (line 4:48).</p>
      <p>VI. RELATED WORK</p>
      <p>With the advent of multi-level modeling, the question of
multi-level model execution emerges. Melanee [1],
DeepTelos [6], MetaDepth [8], DeepJava [7], and XModeler [4] are
modeling tools and frameworks that support model execution,
each pursuing a different strategy with respect to supporting
model execution. Multilevel programming may also be
realized in a type-safe manner by metaprogramming and reflective
constraints [5].</p>
      <p>The Melanee multi-level modeling tool [1] supports model
execution through a service API and a plug-in mechanism. The
communication between modeling and execution environment
can be realized using socket-based communication. Changes
pretty2()
toCurrency2(Currency1) : Currency2</p>
      <sec id="sec-4-1">
        <title>Euro1</title>
      </sec>
      <sec id="sec-4-2">
        <title>Pound1 Yen1</title>
        <p>exchRate = 1 exchRate = 1.12 exchRate = 0.0077
isocode = „EUR“ isocode = „GBP“ isocode = „JPY“</p>
        <p>pretty1-0()</p>
        <p>GBP382000
value = 38200
in the modeling environment then automatically reflect in the
but comes with powerful metamodeling features unmatched
execution environment, and vice versa. The execution
enviby DeepRuby.
ronment can be implemented as a Java program. Concerning
the definition of execution semantics, different approaches
exist. A “pragmatic” approach, for example, employs a Java
representation of the multi-level model where each clabject in
the multi-level model corresponds to a single Java class, with
execution semantics defined using plain Java code.</p>
        <p>DeepTelos [6] extends the Telos metamodeling language
and its implementation with “most general instances” to add
support for deep instantiation. Since DeepTelos defines the
extensions as a set of Datalog axioms, DeepTelos models are
MetaDepth [8] is a text-based multi-level modeling
framework with potency-based deep instantiation. MetaDepth is a
Java-based implementation using a custom syntax. Among the
primary features of MetaDepth are multi-level constraints and
derived attributes at different meta-levels. Execution semantics
is defined using an OCL extension. MetaDepth provides an
interpreter for the thus defined multi-level models. MetaDepth
also supports code generation complying to the Java Metadata
Interface.</p>
        <p>DeepJava [7] is an extension of the Java programming
compatible with ConceptBase, an implementation of a Telos
language with a mechanism for potency-based deep
instanvariant. ConceptBase also allows for the definition of
exetiation. Internally, a compiler transforms DeepJava code into
cutable models using event-condition-action rules. In Sect. IV
plain Java. Hence, each DeepJava class translates into a set
we sketched how to group clabject facets into simple clabjects
of Java classes, one for each clabject facet. The compiler also
that resemble DeepTelos classes. DeepTelos does not directly
generates code for clabject instantiation at runtime, which is
support self-describing clabjects (i.e., clabject with attributes
realized using Java’s reflective functions. Clabject instantiation
where the target potency is higher than the source potency)
results in the dynamic generation of a number of interfaces.
As a limitation, direct access without getters and setters is
restricted to attributes with potency values smaller than two.
With respect to Java, Ruby’s eigenclass concept much better
suits the clabject philosophy of multi-level modeling. As
opposed to DeepJava, DeepRuby supports deep instantiation
with both a source and a target potency, resulting in the
generation of a matrix of Ruby classes for each clabject.</p>
        <p>VII. CONCLUSION</p>
        <p>In this paper we introduced DeepRuby, a Ruby
implementation of the core language constructs of Dual Deep
Instantiation [9]: clabject hierarchies and attributes with dual potencies.
The system takes care of consistent instantiation of clabjects
and attributes and provides methods for querying multi-level
models. Our experiences with implementing DeepRuby have
confirmed our initial conjecture that a dynamic programming
language like Ruby that does not strictly separate classes and
objects is a good platform for implementing clabject-based
modeling constructs.</p>
        <p>In an internal prototype we have also implemented DDI’s
advanced modeling constructs (which are missing from the
DeepRuby version presented in this paper): multi-valued
properties, bi-directional properties, and clabject generalization.
The fine-tuning of the advanced prototype and experimentation
with alternative representations of the clabject facet matrix is
subject to ongoing work.</p>
        <p>Dual deep modeling (DDM) [11], an extended version
of DDI, additionally comes with multi-level cardinality
constraints, property specialization hierarchies, and distinguishes
between property value and property range. Implementing
these constructs in DeepRuby is subject to future work.</p>
        <p>Moving beyond previous implementations of DDI/DDM in
ConceptBase [9] and F-Logic [11], DeepRuby allows to extend
clabject facets with custom methods. We have exemplified
the implementation of such methods and their inheritance and
specialization along the clabject facet hierarchy.</p>
        <p>APPENDIX</p>
        <p>DEEPRUBY IMPLEMENTATION
def facet(srcPtcy,tgtPtcy)
raise "Target potency #{tgtPtcy} above max potency #{model.depth}+1."
if tgtPtcy &gt; (model.depth+1)
return levels[srcPtcy].eigenclassN(tgtPtcy)
end
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def method_missing(method, *args)
if levels[0].respond_to?("#{method}", *args)</p>
        <p>levels[0].send("#{method}", *args)
else</p>
        <p>raise NoMethodError.new("There is no method called #{method} here")
end
end
def define(attribute, srcPtcy, tgtPtcy, value)
for n in (1..(tgtPtcy+1))
obj = facet(srcPtcy,n)
#crete getter
obj.class_eval("
def #{attribute}
if @#{attribute}</p>
        <p>@#{attribute}
else</p>
        <p>inherited(’#{attribute}’)
end
end"
)
#create setter
obj.class_eval("
def #{attribute}=(val)
if valueSettingAllowed(:#{attribute}, val)</p>
        <p>@#{attribute} = val
end
end"
)
end
set(attribute, srcPtcy, tgtPtcy, value)
return self
end
def checkDownwardCompatibility(attribute, srcPtcy, tgtPtcy, value)
return true unless levels[srcPtcy].getMostSpecific(attribute)
return true if value.nil?
for potency in (0..srcPtcy)
getMembersN(potency).each do |cbj|
actMsVal = cbj.levels[srcPtcy-potency]</p>
        <p>.getMostSpecific(attribute)
raise "#{value.name} is not compatible with #{actMsVal.name}" if</p>
        <p>!value.isCompatibleWith( actMsVal )
end
end
end
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
end
end
facet(srcPtcy,tgtPtcy).send("#{attribute}=", value)
return self
end
def get(attribute, srcPtcy, tgtPtcy)</p>
        <p>facet(srcPtcy,tgtPtcy).send(attribute)
end
def getValueSettingObject(attribute, srcPtcy, tgtPtcy)
facet(srcPtcy,tgtPtcy)</p>
        <p>.getValueSettingObject(attribute.to_s.to_sym)
def getMethodDefiningClass(attribute, srcPtcy, tgtPtcy)
facet(srcPtcy,tgtPtcy)</p>
        <p>.method("#{attribute.to_sym}").owner
def to_s
clabjectname = (clabject.respond_to?(:name))? clabject.name : clabject
"#{clabjectname}ˆ(#{srcPtcy},#{tgtPtcy})"
end
end # end Clabject
module ClabjectFacet
attr_accessor(
:clabject,
:srcPtcy,
:tgtPtcy
)
def parent
superclass
end
def eigenclass
singleton_class
end
def inherited(attribute)
if parent.respond_to?(attribute.to_s.to_sym)
parent.send(attribute.to_s.to_sym)
else
false
end
end
def getValueSettingObject(attribute)
if instance_variable_get("@#{attribute.to_sym}")
self
else
getInheritedValueSettingObject(attribute)
end
end
def getInheritedValueSettingObject(attribute)
if parent.respond_to?(attribute.to_s.to_sym)
parent.getValueSettingObject(attribute.to_s.to_sym)
else
false
end
end
def getMostSpecific(attribute)
getMostSpecificN(attribute)[:val]
end
def getMostSpecificN(attribute)
if respond_to?(attribute)
val = self.send(attribute)
if val</p>
        <p>return {:ptcy =&gt; 0, :val =&gt; val}
elsif eigenclass.respond_to?(attribute)
x = eigenclass.getMostSpecificN(attribute) #recursion
if x[:val]</p>
        <p>return {:ptcy =&gt; x[:ptcy]+1, :val =&gt; x[:val]}
end
end
end
return {:val =&gt; false}
end
def valueSettingAllowed(attribute, value)
if value.kind_of?(Clabject)
ms = getMostSpecificN(attribute)
if ms[:val] &amp;&amp; !value.isMemberN( ms[:ptcy], ms[:val] )
raise "#{value.name} is not memberN(#{ms[:ptcy]}) of</p>
        <p>#{ms[:val].name}"
end
return true
else</p>
        <p>raise "#{value} is no Clabject"
end
end
def eigenclassN(n)
obj = self
for m in (1..n) # returns self if n=0</p>
        <p>obj = obj.singleton_class
end
return obj
end</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>Atkinson</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gerbig</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Metzger</surname>
          </string-name>
          , N.:
          <article-title>On the execution of deep models</article-title>
          . In: Mayerhofer,
          <string-name>
            <given-names>T.</given-names>
            ,
            <surname>Langer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            ,
            <surname>Seidewitz</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            ,
            <surname>Gray</surname>
          </string-name>
          ,
          <string-name>
            <surname>J</surname>
          </string-name>
          . (eds.)
          <source>Proceedings of the 1st International Workshop on Executable Modeling. CEUR Workshop Proceedings</source>
          , vol.
          <volume>1560</volume>
          , pp.
          <fpage>28</fpage>
          -
          <lpage>33</lpage>
          . CEUR-WS.org (
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>Atkinson</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          , Ku¨ hne, T.:
          <article-title>The Essence of Multilevel Metamodeling</article-title>
          . In: Gogolla,
          <string-name>
            <given-names>M.</given-names>
            ,
            <surname>Kobryn</surname>
          </string-name>
          , C. (eds.)
          <source>Proceedings of the 4th International Conference on the UML</source>
          <year>2001</year>
          , Toronto, Canada. LNCS, vol.
          <volume>2185</volume>
          , pp.
          <fpage>19</fpage>
          -
          <lpage>33</lpage>
          . Springer Verlag (
          <year>Oct 2001</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>Carvalho</surname>
            ,
            <given-names>V.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Almeida</surname>
            ,
            <given-names>J.P.A.</given-names>
          </string-name>
          :
          <article-title>Toward a well-founded theory for multi-level conceptual modeling</article-title>
          .
          <source>Software &amp; Systems Modeling</source>
          (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <surname>Clark</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gonzalez-Perez</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Henderson-Sellers</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          :
          <article-title>A foundation for multi-level modelling</article-title>
          .
          <source>In: MULTI 2014. CEUR Workshop Proceedings</source>
          , vol.
          <volume>1286</volume>
          , pp.
          <fpage>43</fpage>
          -
          <lpage>52</lpage>
          . CEUR-WS.org (
          <year>2014</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <surname>Draheim</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          :
          <article-title>Reflective constraint writing - A symbolic viewpoint of modeling languages</article-title>
          .
          <source>Trans. Large-Scale Data- and Knowledge-Centered Systems 24</source>
          ,
          <fpage>1</fpage>
          -
          <lpage>60</lpage>
          (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>Jeusfeld</surname>
            ,
            <given-names>M.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Neumayr</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          :
          <article-title>DeepTelos: Multi-level modeling with most general instances</article-title>
          . In:
          <string-name>
            <surname>Comyn-Wattiau</surname>
            ,
            <given-names>I.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Tanaka</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Song</surname>
            ,
            <given-names>I.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Yamamoto</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Saeki</surname>
            ,
            <given-names>M. (eds.) ER</given-names>
          </string-name>
          <year>2016</year>
          .
          <article-title>LNCS</article-title>
          , vol.
          <volume>9974</volume>
          , pp.
          <fpage>198</fpage>
          -
          <lpage>211</lpage>
          . Springer (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <surname>Kuehne</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schreiber</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          :
          <article-title>Can programming be liberated from the twolevel style: Multi-level programming with DeepJava</article-title>
          .
          <source>In: Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-oriented Programming Systems and Applications</source>
          . pp.
          <fpage>229</fpage>
          -
          <lpage>244</lpage>
          (
          <year>2007</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <surname>de Lara</surname>
          </string-name>
          , J.,
          <string-name>
            <surname>Guerra</surname>
          </string-name>
          , E.:
          <article-title>Deep meta-modelling with MetaDepth</article-title>
          . In: Vitek,
          <string-name>
            <surname>J</surname>
          </string-name>
          . (ed.)
          <article-title>TOOLS 2010</article-title>
          .
          <article-title>LNCS</article-title>
          , vol.
          <volume>6141</volume>
          , pp.
          <fpage>1</fpage>
          -
          <lpage>20</lpage>
          . Springer (
          <year>2010</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <surname>Neumayr</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Jeusfeld</surname>
            ,
            <given-names>M.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schrefl</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          , Schu¨ tz, C.:
          <article-title>Dual deep instantiation and its conceptbase implementation</article-title>
          . In: Jarke,
          <string-name>
            <given-names>M.</given-names>
            ,
            <surname>Mylopoulos</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            ,
            <surname>Quix</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            ,
            <surname>Rolland</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            ,
            <surname>Manolopoulos</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            ,
            <surname>Mouratidis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            ,
            <surname>Horkoff</surname>
          </string-name>
          ,
          <string-name>
            <surname>J</surname>
          </string-name>
          . (eds.)
          <source>CAiSE. Lecture Notes in Computer Science</source>
          , vol.
          <volume>8484</volume>
          , pp.
          <fpage>503</fpage>
          -
          <lpage>517</lpage>
          . Springer (
          <year>2014</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <surname>Neumayr</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schuetz</surname>
            ,
            <given-names>C.G.</given-names>
          </string-name>
          :
          <article-title>Multilevel modeling</article-title>
          . In: Liu,
          <string-name>
            <surname>L.</surname>
          </string-name>
          , O¨zsu, M.T. (eds.)
          <source>Encyclopedia of Database Systems</source>
          . pp.
          <fpage>1</fpage>
          -
          <lpage>8</lpage>
          . Springer New York, New York, NY (
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Neumayr</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schuetz</surname>
            ,
            <given-names>C.G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Jeusfeld</surname>
            ,
            <given-names>M.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schrefl</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          :
          <article-title>Dual deep modeling: multi-level modeling with dual potencies and its formalization in F-Logic</article-title>
          .
          <source>Software &amp; Systems</source>
          Modeling pp.
          <fpage>1</fpage>
          -
          <lpage>36</lpage>
          (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>Perrotta</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          :
          <article-title>Metaprogramming Ruby 2</article-title>
          .
          <string-name>
            <given-names>The</given-names>
            <surname>Pragmatic Programmers</surname>
          </string-name>
          (
          <year>2014</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>