goplantuml icon indicating copy to clipboard operation
goplantuml copied to clipboard

Abnormal Display in Interface Implementation via Struct Embedding

Open ZhengweiHou opened this issue 6 months ago • 0 comments

// interface
type IPropertySource interface {
	EqualsName(ps IPropertySource) bool
	GetName() string
	GetSource() map[string]any
	GetProperty(key string) any
	ContainsProperty(key string) bool
}

// 部分实现
type NamedPropertySource struct {
	Name string
}

func (n *NamedPropertySource) GetName() string {
	return n.Name
}

func (n *NamedPropertySource) EqualsName(ps IPropertySource) bool {
	return n.Name == ps.GetName()
}

type PropertySource struct {
	NamedPropertySource // 结构体嵌入
	Source map[string]any
}

func (p *PropertySource) GetSource() map[string]any {
	return p.Source
}

func (p *PropertySource) GetProperty(key string) any {
	return p.Source[key]
}

func (p *PropertySource) ContainsProperty(key string) bool {
	_, ok := p.Source[key]
	return ok
}

Expected PropertySource to implement interface IPropertySource

Image

But the actual display:

Image

ZhengweiHou avatar Apr 25 '25 07:04 ZhengweiHou