Abstract type: Difference between revisions
Content added Content deleted
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
|||
Line 3,220: | Line 3,220: | ||
End Interface</syntaxhighlight> |
End Interface</syntaxhighlight> |
||
=={{header|Vlang}}== |
=={{header|V (Vlang)}}== |
||
{{trans|go}} |
{{trans|go}} |
||
V (Vlang) ''interface type'' is an abstract type. It defines a set of methods that a ''concrete type'' must have to satisfy it. |
|||
A variable of an interface type can hold a value of any type that implements the methods that are specified in the interface. You don't need to explicitly "declare" that the type "implements" the interface or anything like that -- the compatibility is purely structural based on the methods. |
A variable of an interface type can hold a value of any type that implements the methods that are specified in the interface. You don't need to explicitly "declare" that the type "implements" the interface or anything like that -- the compatibility is purely structural based on the methods. |
||
Line 3,228: | Line 3,228: | ||
In the following example, the Dog and Cat types both satisfy the Beast interface because they each have the specified methods. The ''bprint'' function can print details for any Beast. |
In the following example, the Dog and Cat types both satisfy the Beast interface because they each have the specified methods. The ''bprint'' function can print details for any Beast. |
||
<syntaxhighlight lang="vlang">interface Beast { |
<syntaxhighlight lang="v (vlang)">interface Beast { |
||
kind() string |
kind() string |
||
name() string |
name() string |