Advertisement
Guest User

Untitled

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