Revision 8a57f3b03992351f46c4537fd0d9351592278d2b (click the page title to view the current version)

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.


var gwr=document.getElementById('graphWithRefs0'); gwr.style.display='block'; gwr.scrollLeft=this.scrollLeft; this.style.display='none'; var gwr=document.getElementById('graphWithRefs0'); gwr.style.display='block'; gwr.scrollLeft=this.scrollLeft; this.style.display='none'; -4,4 -4,-140.85 318.25,-140.85 318.25,4 -4,4 c0_Book abstract Book 11.00 c0_Author abstract Author : Person 11.00 c0_Book->c0_Author author transparent c0_Author->c0_Book book transparent c0_Person abstract Person 11.00 c0_Author->c0_Person 143.57,-110.68 147.07,-120.68 150.57,-110.68 143.57,-110.68 c0_GenerativeProgramming GenerativeProgramming : Book 11.00 c0_GenerativeProgramming->c0_Book 233.57,-25.63 237.07,-35.63 240.57,-25.63 233.57,-25.63 c0_Czarnecki Czarnecki : Author 11.00 c0_Czarnecki->c0_Author 120.36,-83.02 130.91,-83.95 123.24,-76.64 120.36,-83.02 c0_Eisenecker Eisenecker : Author 11.00 c0_Eisenecker->c0_Author
Module Statistics: | All clafers: 27 | Abstract: 3 | Concrete: 24 | Reference: 10 | Constraints: 13 | Goals: 0 | Global scope: 1..* | Can skip name resolver: no |

Module Downloads: | [.cfr] | [.html] |

nextExercise - Alternative Ways of Modeling


Back Exercise - Modeling a Concept

Back Clafer a bit more precisely

Back Introduction