Notation
The notation currently used in AlphaSimple is TextUML, a textual notation for UML. This page is not a replacement for the TextUML documentation, but it instead demonstrates how to use that notation when creating models for AlphaSimple.
Before you start, make sure you sign up for AlphaSimple, so you can put what you learned to practice right away!
Entity and properties
This simple model shows an entity with a couple of properties, one required (name) and another optional (birthDate):
class Customer
attribute name : String;
attribute birthDate : Date[0,1];
end;
end.
As you can tell, AlphaSimple maps TextUML/UML classes to entities. Note also that AlphaSimple currently does not support multivalued properties.
Relationships
This model is a bit more elaborate and shows three entities connected via two relationships, one, mandatory and single (Expense’s category), and another, multiple and optional (Employee’s expenses).
class Category
attribute name : String;
end;
class Expense
attribute amount : Double;
attribute date : Date;
reference category : Category;
end;
class Employee
attribute name : String;
reference expenses : Expense[*];
end;
end.
Relationships can be defined in other ways. See the TextUML documentation on associations for more information.
Actions
The model below shows actions defined on an entity:
class Account
attribute number : String;
attribute balance : Double;
operation deposit(amount : Double);
begin
self.balance := self.balance + amount;
end
operation withdraw(amount : Double);
begin
self.balance := self.balance - amount;
end;
end;
end.
Queries
You can use queries with and without parameters:
class Account
attribute number : String;
attribute balance : Double;
static operation accountsInGoodStanding() : Account[*];
begin
return Account extent.select(
(a : Account) : Boolean {
return a.balance >= 0;
}
);
end;
static operation bestAccounts(cutOff : Double) : Account[*];
begin
return Account extent.select(
(a : Account) : Boolean {
return a.balance >= cutOff;
}
);
end;
end;
end.
Queries are represented in TextUML as static operations that return entities. Queries often start from an entity extent (akin to SQL’s ’select * from…’), and then filter from there.’
What next?
Hope you had fun trying these examples in AlphaSimple. Now extend them with your own ideas! Or if you feel adventurous, try the advanced examples.
