--- title: Exercise - Example Reference Solution ... ```clafer 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 ] ``` ```clafer abstract Person // a template for a person name -> string dob -> string ? // of course the person always has dob but for our application it is possible not to give it ``` ```clafer abstract Author : Person // author is a special person who has at least one book book -> Book + // book has to point at least one concrete book ``` ```clafer GenerativeProgramming : Book // a concrete example of a book [ title = "Generative Programming" ] [ year = 2000 ] [ # page = 589 ] // number (#) of instances of page is 589 [ paper ] // because the book is paper it automatically also has a format [ nonfiction ] // because the book is nonfiction it automatically also has a kind [ author = Czarnecki, Eisenecker ] // Czarnecki and Eisenecker are the authors [ ISBN = "0201309775" ] // there's no GS1 prefix, which is ok because the year is < 2007 ``` ```clafer Czarnecki : Author [ name = "Krzysztof Czarnecki" ] [ GenerativeProgramming in book ] // GenerativeProgramming is one of Czarnecki's books ``` ```clafer Eisenecker : Author [ name = "Urlich Eisenecker" ] [ GenerativeProgramming in book ] ``` To instantiate this model, you have to set the scope for `page` to `589` and set `max int` to `2007`. ```{.clafer .ide} ``` ```{.clafer .summary} ``` ![next](/next.png)[Exercise - Alternative Ways of Modeling]() -------------------- > Back [Exercise - Modeling a Concept]() > Back [Clafer a bit more precisely](ClaferMorePrecisely) > Back [Introduction](Intro)