Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.util.Random
- object Main {
- @main def test(): Unit = {
- val printer = Printer()
- val scanner = Scanner()
- val copyMachine = CopyMachine(printer, scanner)
- val file = copyMachine.scanFile()
- copyMachine.printFile(file)
- copyMachine.copy()
- //copyMachine.glitch() - don't compile
- }
- class Printer {
- def printFile(file: String): Unit =
- println(s"Printing $file.")
- def glitch(): Unit =
- println("Glitchy printer")
- }
- class Scanner {
- def scanFile(): String = {
- println("Scanning file")
- Random.nextString(10)
- }
- }
- class CopyMachine(printer: Printer, scanner: Scanner) {
- export printer.{glitch => _, *}
- export scanner.*
- def copy(): Unit = printFile(scanFile())
- }
- }
Add Comment
Please, Sign In to add comment