2019-07-03 22:53:25 +03:00
|
|
|
struct Dog {
|
2019-09-04 18:49:46 +03:00
|
|
|
breed string
|
2019-07-03 22:53:25 +03:00
|
|
|
}
|
|
|
|
|
2019-11-08 06:03:06 +03:00
|
|
|
struct Cat {
|
|
|
|
breed string
|
2019-07-03 22:53:25 +03:00
|
|
|
}
|
|
|
|
|
2019-11-08 06:03:06 +03:00
|
|
|
|
|
|
|
fn (d Cat) name() string { return 'Cat' }
|
|
|
|
fn (d Cat) speak() { println('meow') }
|
|
|
|
|
|
|
|
fn (d Dog) speak() { println('woof') }
|
|
|
|
fn (d Dog) name() string { return 'Dog'}
|
2019-07-03 22:53:25 +03:00
|
|
|
|
|
|
|
interface Speaker {
|
|
|
|
name() string
|
2019-08-31 16:38:13 +03:00
|
|
|
speak()
|
2019-07-03 22:53:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Speak2er {
|
|
|
|
name() string
|
2019-11-08 06:03:06 +03:00
|
|
|
speak()
|
2019-07-03 22:53:25 +03:00
|
|
|
}
|
|
|
|
|
2019-11-08 06:03:06 +03:00
|
|
|
struct Foo {
|
|
|
|
speaker Speaker
|
2019-11-08 17:59:01 +03:00
|
|
|
speakers []Speaker
|
2020-03-14 16:19:56 +03:00
|
|
|
}
|
2019-11-08 06:03:06 +03:00
|
|
|
|
2019-11-08 07:43:44 +03:00
|
|
|
fn perform_speak(s Speaker) {
|
2019-07-03 22:53:25 +03:00
|
|
|
s.speak()
|
2019-11-08 07:43:44 +03:00
|
|
|
assert true
|
|
|
|
name := s.name()
|
|
|
|
assert name == 'Dog' || name == 'Cat'
|
2020-03-14 16:19:56 +03:00
|
|
|
println(s.name())
|
2019-07-03 22:53:25 +03:00
|
|
|
}
|
|
|
|
|
2019-11-08 17:59:01 +03:00
|
|
|
fn perform_speakers(speakers []Speaker) {
|
2020-03-14 16:19:56 +03:00
|
|
|
|
|
|
|
}
|
2019-11-08 17:59:01 +03:00
|
|
|
|
2019-07-03 22:53:25 +03:00
|
|
|
fn test_perform_speak() {
|
2019-11-08 17:59:01 +03:00
|
|
|
dog := Dog{}
|
|
|
|
perform_speak(dog)
|
2019-11-08 06:03:06 +03:00
|
|
|
cat := Cat{}
|
2019-11-08 07:43:44 +03:00
|
|
|
perform_speak(cat)
|
2019-11-08 17:59:01 +03:00
|
|
|
//perform_speakers([dog, cat])
|
|
|
|
/*
|
2019-11-08 06:03:06 +03:00
|
|
|
f := Foo {
|
2019-11-08 17:59:01 +03:00
|
|
|
speaker: dog
|
2020-03-14 16:19:56 +03:00
|
|
|
}
|
2019-11-08 17:59:01 +03:00
|
|
|
*/
|
2019-11-08 06:03:06 +03:00
|
|
|
|
2019-07-03 22:53:25 +03:00
|
|
|
}
|
|
|
|
|
2019-11-20 18:19:13 +03:00
|
|
|
interface Register {
|
|
|
|
register()
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RegTest {a int}
|
|
|
|
|
|
|
|
fn (f RegTest) register() {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_reg(r Register) {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_register() {
|
|
|
|
f := RegTest{}
|
|
|
|
f.register()
|
|
|
|
handle_reg(f)
|
|
|
|
}
|