Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.50 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. type Common interface {
  6.     Show()
  7. }
  8.  
  9.  
  10. type abstractCommon struct {
  11.     Common
  12.     field string
  13. }
  14.  
  15. func (c *abstractCommon) Show() {
  16.     fmt.Println(c.field)
  17. }
  18.  
  19. type A struct {
  20.     abstractCommon
  21. }
  22.  
  23. type B struct {
  24.     abstractCommon
  25. }
  26.  
  27. func NewA(f string) *A {
  28.     a := A{abstractCommon{field: f}}
  29.     return &a
  30. }
  31.  
  32. func NewB(f string) *B {
  33.     b := B{abstractCommon{field: f}}
  34.     return &b
  35. }
  36.  
  37. func main() {
  38.     a := NewA("a")
  39.     a.Show()
  40.  
  41.     b := NewB("b")
  42.     b.Show()
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement