2008-06-06 15:27:34 -06:00
|
|
|
// $G $D/$F.go && $L $F.$A && ./$A.out
|
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
type Iputs interface
|
|
|
|
{
|
2008-09-05 20:50:34 -06:00
|
|
|
puts (s string);
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
|
|
|
|
|
|
|
type Print struct
|
|
|
|
{
|
|
|
|
whoami int;
|
|
|
|
put Iputs;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Print)
|
|
|
|
dop()
|
|
|
|
{
|
2008-08-11 23:07:49 -06:00
|
|
|
print(" print ", p.whoami);
|
2008-06-06 15:27:34 -06:00
|
|
|
p.put.puts("abc");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
|
|
|
|
|
|
|
type Bio struct
|
|
|
|
{
|
|
|
|
whoami int;
|
|
|
|
put Iputs;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Bio)
|
|
|
|
puts(s string)
|
|
|
|
{
|
2008-08-11 23:07:49 -06:00
|
|
|
print(" bio ", b.whoami);
|
2008-06-06 15:27:34 -06:00
|
|
|
b.put.puts(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
|
|
|
|
|
|
|
type File struct
|
|
|
|
{
|
|
|
|
whoami int;
|
|
|
|
put Iputs;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *File)
|
|
|
|
puts(s string)
|
|
|
|
{
|
2008-08-11 23:07:49 -06:00
|
|
|
print(" file ", f.whoami, " -- ", s);
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
p := new(Print);
|
|
|
|
b := new(Bio);
|
|
|
|
f := new(File);
|
|
|
|
|
|
|
|
p.whoami = 1;
|
|
|
|
p.put = b;
|
|
|
|
|
|
|
|
b.whoami = 2;
|
|
|
|
b.put = f;
|
|
|
|
|
|
|
|
f.whoami = 3;
|
|
|
|
|
|
|
|
p.dop();
|
2008-08-11 23:07:49 -06:00
|
|
|
print("\n");
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|