File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ Goではとても繊細なinterfaceと呼ぶべき設計があります。これ
11
11
12
12
Studentには3つのメソッドがあることになります:SayHi、Sing、BorrowMoneyです。EmployeeはSayHi、Sing、SpendSalaryです。
13
13
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メソッドを持っていないからです 。
15
15
### interface型
16
16
interface型ではメソッドのセットを定義します。もしあるオブジェクトがインターフェースとなるすべてのメソッドを実装するとしたら、このオブジェクトはこのインターフェースを実装することになります。細かい文法は下の例を参考にしてください。
17
17
@@ -268,7 +268,7 @@ interfaceの変数の中にはあらゆる型の数値を保存できること
268
268
} else if value, ok := element.(Person); ok {
269
269
fmt.Printf("list[%d] is a Person and its value is %s\n", index, value)
270
270
} else {
271
- fmt.Println ("list[%d] is of a different type", index)
271
+ fmt.Printf ("list[%d] is of a different type\n ", index)
272
272
}
273
273
}
274
274
}
You can’t perform that action at this time.
0 commit comments