Skip to content

Commit

Permalink
add syntax examples for USE classes and associations
Browse files Browse the repository at this point in the history
  • Loading branch information
escribis committed Apr 12, 2016
1 parent c10615b commit 98fa0e1
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 6 deletions.
17 changes: 17 additions & 0 deletions useocl/docs/examples/association_class.use
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
model jungle_association_class

class Monkey
end

class Snake
end

associationclass Hate between
Monkey [*] role monkeys
Snake [*] role snakes
attributes
reason : String
intensity : Integer
operations
increase()
end
16 changes: 16 additions & 0 deletions useocl/docs/examples/jungle_classes.use
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
model jungle_class

class Yellow
end

abstract class Something
end

abstract class Fruit < Something
end

class Banana < Fruit, Yellow
end

class Orange < Fruit
end
109 changes: 103 additions & 6 deletions useocl/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ just type::

The Graphical User Interface.


Documentation
-------------

Expand Down Expand Up @@ -135,38 +134,136 @@ Only particular points are exemplified below.
Enumerations
""""""""""""

In USE enumerations can be defined as following::
USE::

enum Season {winter, autumn, spring, summer}

In USE or SOIL enumerations can be used as following::
SOIL/USE::

Season::winter

Classes
"""""""
Classes can be defined as following::

class Yellow
end

abstract class Something
end

abstract class Fruit < Something
end

class Banana < Fruit, Yellow
end

UML:

.. image:: media/USEOCLClasses.png
:align: center

Attributes
""""""""""

::

class Banana
attributes
length : Integer /* Integer, Real, Boolean, String */
growthTime : Season
-- Tuple, Bag, Set, OrderedSet, Sequence
goodies : OrderedSet(Bag(Sequence(Set(Tuple(x:Integer,y:Real,z:String)))))

remainingDays : Integer
init: 42 -- attribute initialization
derived: self.length * self.size -- attribute derivation

end

Restriction form the standard
* No invariants directly declared on attributes
* No cardinality supported for attributes. For instance ``smoker : Boolean[0..1]`` is not supported.

Operations
""""""""""
::

class Banana
operations

sleep() -- operation signature

wakeUp(n : Integer):String -- operation specification
pre notTooMuch: n > 10 and n < self.length -- precondition
post resultOK: result > 'anaconda' -- pôstcondition

helloJungle() : String -- operation implementation (SOIL)
begin
declare x : Banana ;
WriteLine('hello') ;
x := new Banana ;
self.length := self.length + self.remainingDays*20+3 ;
result := 'jungle' ;
destroy x ;
end
pre freshEnough: self.remainingDays > 10

smash() : Integer -- operation/query (OCL)
= self.length + Set{4,2}->size*42
end

Associations
""""""""""""

Here is an example of (regular) *association*:
UML:

.. image:: media/USEOCLAssociationUSE.png
:align: center

In USE::
USE::

association Owns between
Person [1] role owner
Car[*] role ownedCars
-- more roles for n-ary association
end

An example of link:

.. image:: media/USEOCLAssociationSOIL.png
:align: center

In SOIL::
SOIL::

! insert(tian,c232) into Owns

Association Classes
"""""""""""""""""""

UML:

.. image:: media/USEOCLAssociationClassUSE.png
:align: center

USE::

associationclass Hate between
Monkey [*] role monkeys
Snake [*] role snakes
attributes
reason : String
intensity : Integer
operations
increase()
end


SOIL::

! c := new Hate between (chita,kaa)
! c.reason := "kaa is really mean"
! c.intensity = 1000

Qualified Associations
""""""""""""""""""""""
Expand Down
Binary file added useocl/media/USEOCLAssociationClassUSE.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added useocl/media/USEOCLClasses.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 98fa0e1

Please sign in to comment.