Let’s say we want to implements the a cache functionality.

// memory.go

package cache

type memoryCache struct {
    data map[string]string
}

func (m *memoryCache) Get(key string) (string, bool) {
    v, ok := m.data[key]
    return v, ok
}

func (m *memoryCache) Set(key, value string) {
    m.data[key] = value
}

// cache.go

package cache

type Cache interface {
    Get(key string) (string, bool)
    Set(key, value string)
}

// factory.go

package cache

func NewCache() Cache {
    return &memoryCache{
        data: make(map[string]string),
    }
}

by returning the interface object from the factory method NewCache method, this approach introduces many flaws in the design.

Problem 1:

let’s say we implemented struct method with name