If I have the following interface and struct:
package shape
type Shape interface {
Area()
}
type Rectangle struct {
}
func (this *Rectangle) Area() {}
func New() Shape {
return &Rectangle{}
}
Then how can I add the New()
method (as a constructor) into the interface Shape
?
The use case is that if I have another struct Square
type Square struct {
Rectangle
}
Then the Square
will have a method Area()
. But it won't have New()
. My purpose is let any struct which inherits Shape
has a New()
method automatically. How can I do that?