Jump to content

Abstract type: Difference between revisions

→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)"
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
Line 3,220:
End Interface</syntaxhighlight>
 
=={{header|V (Vlang)}}==
{{trans|go}}
VlangsV (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.
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.
 
<syntaxhighlight lang="v (vlang)">interface Beast {
kind() string
name() string
451

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.