Abstract type: Difference between revisions

no edit summary
m (→‎{{header|Phix}}: added syntax colouring the hard way)
No edit summary
Line 324:
return
</lang>
=={{header|BASIC}}==
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
BBC BASIC is a procedural language with no built-in OO features. The CLASSLIB library implements simple Object Classes with multiple inheritance; an abstract class may be created without any instantiation, the sole purpose of which is for other classes to inherit from it. At least one member or method must be declared, but no error will be generated if there is no implementation:
Line 347:
REM Test by calling the method:
PROC(instance.method)</lang>
==={{header|QB64}}===
QB64, along with QBasic and QuickBasic (without extension), is not Object-Oriented; however, the following addresses issues raised in the description of the problem as well as the problem itself:
<lang QB64>'Keep in mind that this code DOES NOT follow appropriate coding structure, but is used for easiest explanation. That
'said, the following is both legal and executable.
 
a = 15 'Addressing the point raised regarding hiding complexity from the programmer, QB64 follows the QBasic/QuickBasic paradigm
'of not requiring the programmer to declare the type of a variable at all. In fact, variables can be used without any prior
'declaration or DIMensioning. So, in this way an undeclared variable is somewhat similar to a VOID in C/C++; however,
'unlike a VOID, the undeclared variable in QB64 DOES have a type, but the programmer need not be concerned with what it is.
 
Type c 'The closest to having Classes QB64 comes, being not OO, is user-defined types, which are containers of multiple
'values of same or different types. This is a declaration of a user-defined type named "c" which has the
'following elements:
d As Integer 'This is the declaration of variable "d", which is an element (notice the lack of the use of the word "member") of
'the user-defined type "c".
e As String 'As mentioned above the user-defined type, in this case "c", can have constituent elements of differing types.
End Type 'Notice that since this is a user-defined type and not an object, there are no methods defined within it.
 
 
Type f 'As QB64 is not OO, it does not have true inheritence; however, the nesting of user-defined types is allowed, which
'allows for an attempt at inheritance, as close as QB64 can come. As well as pseudo-abstracting the type "c", which
'need not ever be directly accessed, although since instantiation occurs at declaration, memory allocation is most
'likely made for it.
g As c 'This is the declaration of a user-defined type as an element of another user-defined type. If "c" were used
'nowhere else in the program, but only here as a variable type, the pseudo-abstraction is achieved.
h As Integer
End Type
 
c.d = 25 'This is the way in which elements of user-defined types are accessed. Here the type "c" has been directly accessed
'and thus eliminates any such pseudo-abstraction as mentioned above.
 
Dim i As f 'This is the declaration of a variable of the user-defined type "f", which allows for the following.
i.g.e = "thirty five" 'This is the way in which the element of a user-define type containing another user-defined type as an
'element is access. In this way, user-defined type "f" has been pseudo-abstracted since its elements are
'never directly referenced in the rest of this program, even though memory has been allocated for it and its
'constituent elements.
 
Print a
Print b
Print c.d
Print c.e
Print i.g.e 'This is another use of the previously declared variable "i" and its element "g"'s element "e".
Print g.e 'This is NOT a use of the above variable "i" or any of its elements. Since QB64 does not require strict typing
'nor contain a typeOf() function, it is unclear of what type "g.e" is, although it is suspected that it is either
'an Integer or a String, being a use of type "c"'s element "d" or "e".
System </lang>
 
=={{header|C}}==