# Exercise - Example Reference Solution

abstract Book// a template for a book
title -> string// a title can hold a text value
subtitle -> string ?// subtitle is optional
year -> integer// year has a numeric value
page 2..* // at least 2 pages
xor format// a book can be in only one format at a time
paper
hardcover ?// hardcover is optional and only makes sense when the book is paper
electronic
xor kind// a book can be of one kind at a time
textbook
manual
reference
fiction
nonfiction
other -> string// other allows giving a kind in text
author -> Author +// author points at least one author of the book
[ year >= 1970 => ISBN ]
ISBN -> string ?// it is currently not possible to specify in Clafer that ISBN has 10 digits
GS1 -> string ?
[ year >= 2007 => GS1 ]
abstract Person
name -> string// a template for a person
dob -> string ?
abstract Author : Person// of course the person always has dob but for our application it is possible not to give it
book -> Book +
GenerativeProgramming : Book// author is a special person who has at least one book
[ title = "Generative Programming" ]// book has to point at least one concrete book
[ year = 2000 ]
[ # page = 589 ]// a concrete example of a book
[ paper ]
[ author = Czarnecki, Eisenecker ]// number (#) of instances of page is 589
[ ISBN = "0201309775" ]// because the book is paper it automatically also has a format
Czarnecki : Author// because the book is nonfiction it automatically also has a kind
[ name = "Krzysztof Czarnecki" ]// Czarnecki and Eisenecker are the authors
[ GenerativeProgramming in book ]// there's no GS1 prefix, which is ok because the year is < 2007
Eisenecker : Author
[ name = "Urlich Eisenecker" ]
// GenerativeProgramming is one of Czarnecki's books

To instantiate this model, you have to set the scope for page to 589 and set max int to 2007.

Module Statistics: | All clafers: 27 | Abstract: 3 | Concrete: 24 | Reference: 10 | Constraints: 13 | Goals: 0 | Global scope: 1..* | Can skip name resolver: no |