Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. type base interface {
  2. func1()
  3. func2()
  4. common_func()
  5. }
  6.  
  7. type derived1 struct {
  8. base // anonymous meaning inheritence
  9. data DatumType
  10. }
  11.  
  12. type derived2 struct {
  13. base // anonymous meaning inheritence
  14. data DatumType
  15. }
  16.  
  17. type base struct{
  18. data DatumType
  19. }
  20. func (b base) func1(){
  21.  
  22. }
  23.  
  24. func (b base) func2(){
  25.  
  26. }
  27.  
  28. func (b base) common_func(){
  29.  
  30. }
  31.  
  32. type derived1 struct {
  33. base // anonymous meaning embedding
  34. }
  35.  
  36. type derived2 struct {
  37. base // anonymous meaning embedding
  38. }
  39.  
  40. d := derived1{}
  41. d.func1()
  42. d.func2()
  43. d.common_func()
  44.  
  45. d.base.data = something
  46.  
  47. type common struct {
  48. data DatumType
  49. }
  50.  
  51. func (c *common) commonFunc() {
  52. // Do something with data.
  53. }
  54.  
  55. type derived1 struct {
  56. common
  57. otherField1 int
  58. }
  59.  
  60. // Implement other methods on derived1.
  61.  
  62. type derived2 struct {
  63. common
  64. otherField2 string
  65. }
  66.  
  67. // Implement other methods on derived2.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement