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 new function ...)

Many thanks for your help

< P> What interface do you have (Which allows one to pass an object as an interface, because the object is a receiver for all interface methods).
Here, which is not helpful here.

This is more (by using one for example):

Promote common field number of edges for both the structure . The:

A struct x code> called promotion .

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:

  Square & amp; {Shape: {Edge count: 4}} Triangle & amp; {Size} {edges: 3}}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -