Skip to content

Commit 2f3886a

Browse files
authored
Merge pull request astaxie#878 from 38elements/02.6
Update ja/02.6.md
2 parents ab2a632 + d37a770 commit 2f3886a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ja/02.6.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Goではとても繊細なinterfaceと呼ぶべき設計があります。これ
1111

1212
Studentには3つのメソッドがあることになります:SayHi、Sing、BorrowMoneyです。EmployeeはSayHi、Sing、SpendSalaryです。
1313

14-
上のような組み合わせをinterface(オブジェクトStudentとEmployeeに追加されます)と言います。例えばStudentとEmployeeでどちらもinterfaceであるSayHiとSingを実装します。この2つのオブジェクトはこのinterface型です。EmployeeはこのinterfaceであるSayHi、SingとBorrowMoneyは実装しません。EmployeeはBorrowMoneyメソッドを実装しないからです
14+
このようなメソッドの組み合わせはinterfaceと呼ばれます。そして、それらはStudentとEmployeeで実装されます。StudentとEmployeeはinterfaceのSayHiとSingを実装します。同時にEmployeeはBorrowMoneyを実装しません。そして、StudentはSpendSalaryを実装しません。なぜなら、EmployeeはBorrowMoneyメソッドを持っていません。また、StudentはSpendSalaryメソッドを持っていないからです
1515
### interface型
1616
interface型ではメソッドのセットを定義します。もしあるオブジェクトがインターフェースとなるすべてのメソッドを実装するとしたら、このオブジェクトはこのインターフェースを実装することになります。細かい文法は下の例を参考にしてください。
1717

@@ -268,7 +268,7 @@ interfaceの変数の中にはあらゆる型の数値を保存できること
268268
} else if value, ok := element.(Person); ok {
269269
fmt.Printf("list[%d] is a Person and its value is %s\n", index, value)
270270
} else {
271-
fmt.Println("list[%d] is of a different type", index)
271+
fmt.Printf("list[%d] is of a different type\n", index)
272272
}
273273
}
274274
}

0 commit comments

Comments
 (0)