Migrate code examples to Scala classes, close #2432