Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- type Common interface {
- Show()
- }
- type abstractCommon struct {
- Common
- field string
- }
- func (c *abstractCommon) Show() {
- fmt.Println(c.field)
- }
- type A struct {
- abstractCommon
- }
- type B struct {
- abstractCommon
- }
- func NewA(f string) *A {
- a := A{abstractCommon{field: f}}
- return &a
- }
- func NewB(f string) *B {
- b := B{abstractCommon{field: f}}
- return &b
- }
- func main() {
- a := NewA("a")
- a.Show()
- b := NewB("b")
- b.Show()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement