# FamiliesToPersons Model Transformation in Clafer

An example FamiliesToPersons inspired by ATL/Tutorials - Create a simple ATL transformation. We let the reader appreciate the simplicity, conciseness, and declarative nature of this transformation in Clafer.

First, we specify the Family model.

enum Gender = male | female
abstract Family
familyName -> string
members -> Member +
[ this.lastName = familyName ]
abstract Member
lastName -> string
firstName -> string
gender -> Gender

Now, let’s create two sample families: the Browns and the Smiths.

theBrowns : Family
[ familyName = "Brown" ]
[ members = John ]
John : Member
[ firstName = "John" ]
[ gender = male ]
theSmiths : Family
[ familyName = "Smith" ]
[ members = Alice, Bob ]
Alice : Member
[ this.firstName = "Alice" ]
[ this.gender = female ]
Bob : Member
[ this.firstName = "Bob" ]
[ this.gender = male ]

Next, we specify the Person model. Persons point to Members and have the corresponding first and last names.

abstract Person -> Member
fName -> string = this.firstName
lName -> string = this.lastName

Males are persons whose gender is male.

Male : Person 2..*
[ this.gender = male ]

Analogously, Feamales.

Female : Person +
[ this.gender = female ]

Now, we’re ready to specify the actual model transformation which maps male Members to Males and female Members to Females.

[ all member : Member | member.gender.dref = male => one m : Male | m.dref = member ]
[ all member : Member | member.gender.dref = female => one m : Female | m.dref = member ]

When instantiating this model (e.g., using the ClaferIDE), the following result is generated:

=== Instance 1 ===

The inputs

female
male
theBrowns
John
lastName$1 = "Brown" firstName$1 = "John"
gender$1 = male familyName$1 = "Brown"
members$1 = John theSmiths Alice lastName$2 = "Smith"
firstName$2 = "Alice" gender$2 = female
Bob
lastName$3 = "Smith" firstName$3 = "Bob"
gender$3 = male familyName$2 = "Smith"
members$2 = Bob members$3 = Alice

The result

Female = Alice
fName$1 = "Alice" lName$1 = "Smith"
Male$1 = John fName$2 = "John"
lName$2 = "Brown" Male$2 = Bob
fName$3 = "Bob" lName$3 = "Smith"