Repository navigation
Abstract
Home › User Defined Types › Abstract
Declare abstract methods
Type typename Extends base_typename
Declare Abstract Sub|Function|Property|Operator ...
End TypeAbstract is a special form of Virtual. The difference is that abstract methods do not have a body, but just the declaration. Essentially this allows the declaration of an interface which can be implemented by various derived types.
In order to call an abstract method, it must have been overridden and implemented by a derived data type, or else the program will abort.
As a result, only types that implement all the abstract methods are allowed to create objects. For the same reason, a constructor should not call an unimplemented method.
Constructors cannot be abstract, since they cannot be virtual. In addition, abstract Destructors are not supported either, because a destructor body (no matter whether implicit or explicit) is needed in order to call base and field destructors.
Abstracts are called "pure virtual" in C++ (unlike FreeBASIC, C++ allows pure virtuals to have a body, but accessible only statically).
Note: In a multi-level inheritance, a same named method (same identifier and signature) can be declared Abstract, Virtual or normal (without specifier) at each inheritance hierarchy level. When there is mixing of specifiers, the usual order is abstract -> virtual -> normal, from top to bottom of the inheritance hierarchy.
The access control (Public/Protected/Private) of an overriding method is not taken into account by the internal polymorphism process, but only for the initial call at compile-time.
A derived static method cannot override a base virtual/abstract method, but can shadow any base method (including virtual/abstract).
- Only available in the -lang fb dialect.
- New to FreeBASIC
Type Hello Extends Object
Declare Abstract Sub hi( )
End Type
Type HelloEnglish Extends Hello
Declare Sub hi( )
End Type
Type HelloFrench Extends Hello
Declare Sub hi( )
End Type
Type HelloGerman Extends Hello
Declare Sub hi( )
End Type
Sub HelloEnglish.hi( )
Print "hello!"
End Sub
Sub HelloFrench.hi( )
Print "Salut!"
End Sub
Sub HelloGerman.hi( )
Print "Hallo!"
End Sub
Randomize( Timer( ) )
Dim As Hello Ptr h
For i As Integer = 0 To 9
Select Case( Int( Rnd( ) * 3 ) + 1 )
Case 1
h = New HelloFrench
Case 2
h = New HelloGerman
Case Else
h = New HelloEnglish
End Select
h->hi( )
Delete h
NextCategory: User Defined Types
Kind: type
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing