Text not verified for kermeta 2 | |
---|---|
Users of modern programming languages, like Java, would feel easy with object-oriented features in Kermeta: classes, inheritance, exceptions, and even genericity.
// persons who write documents class Writer { attribute name : kermeta::standard::String } // generic concept for every document abstract class Document { reference author : Writer attribute text : kermeta::standard::String } // a "Document" from the real world class Book inherits Document {} // a specialized "Book" class ChildBook inherits Book { attribute minimalAge : kermeta::standard::Integer }
Such classes can be used for verifications:
// a specialized Exception class AgeException inherits kermeta::exceptions::Exception {} abstract class Reader { operation read(book : ChildBook) : Void is abstract } class Child inherits Reader { attribute age : kermeta::standard::Integer operation initialize(age : kermeta::standard::Integer) : Child is do self.age := age result := self // return self so we can chain this call directly after a new end // an action which triggers an Exception operation read(book : ChildBook) : Void is do if age < book.minimalAge then raise AgeException.new end end }
You can get more informations about Kermeta object-oriented features in Chapter 2, Reference . More precisely in