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
|
|
|
|
|
2009-01-20 15:40:40 -07:00
|
|
|
type Iputs interface
|
2008-06-06 15:27:34 -06:00
|
|
|
{
|
2008-09-05 20:50:34 -06:00
|
|
|
puts (s string);
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
|
|
|
|
2009-01-20 15:40:40 -07:00
|
|
|
type Print struct
|
2008-06-06 15:27:34 -06:00
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
|
|
|
|
2009-01-20 15:40:40 -07:00
|
|
|
type Bio struct
|
2008-06-06 15:27:34 -06:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
|
|
|
|
2009-01-20 15:40:40 -07:00
|
|
|
type File struct
|
2008-06-06 15:27:34 -06:00
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
2009-01-06 16:19:02 -07:00
|
|
|
p := new(Print);
|
|
|
|
b := new(Bio);
|
|
|
|
f := new(File);
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
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
|
|
|
}
|