update: interface promoted methods

This commit is contained in:
Inanc Gumus
2019-09-02 16:48:38 +03:00
parent fcf5a8a791
commit 83b32e4170
8 changed files with 4 additions and 9 deletions

View File

@ -9,11 +9,12 @@ package main
import "fmt" import "fmt"
type printer interface { type item interface {
print() print()
discount(float64)
} }
type list []printer type list []item
func (l list) print() { func (l list) print() {
if len(l) == 0 { if len(l) == 0 {
@ -27,13 +28,7 @@ func (l list) print() {
} }
func (l list) discount(ratio float64) { func (l list) discount(ratio float64) {
type discounter interface {
discount(float64)
}
for _, it := range l { for _, it := range l {
if it, ok := it.(discounter); ok {
it.discount(ratio) it.discount(ratio)
} }
} }
}