Understanding interfaces in Go -
I'm trying to understand how that is known.
Say I have 2 strings:
Now I am creating a size < / Code> Interface:
Type size interface {} Why can not I tell that the size interface is in a < Code> EgdesCount property? Interface is only to reconstruct methods?
Whatever problem I have is sharing the function. It is not possible to come up with something like this:
func new () * size {s: = new (shape) s.edgesCount = 0 return s} This will be better than rewriting the exact code:
func new () * square {s: = new (s)) s.edgesCount = 0 return s} ) * Triangle {s: = new (triangle) s.edgesCount = 0 return s} (which is also a problem problem because I do not redeclare my Many thanks for your help This is more (by using one for example): Promote common field A See type shape structure {edgesCount int} type class structure {shape} type triangle structure {shape} func NewSquare () * square {returns and square} {shape} edges : 4},}} Function nitricell () * triangle {return and triangle} {shape} edges: 3}}}} fancy main () {fmt.printf ("square% v \ n", new.square ()) fmt .printf ("triangle% + v \ n", naturangle ())} Output: new function ...)
Here, which is not helpful here. number of edges for both the structure . The: struct x code> called promotion .
Square & amp; {Shape: {Edge count: 4}} Triangle & amp; {Size} {edges: 3}}
Comments
Post a Comment