Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Modula-3
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Object-oriented=== Object-oriented programming techniques may be used in Modula-3, but their use is not a requirement. Many of the other features provided in Modula-3 (modules, generics) can usually take the place of object-orientation. Object support is intentionally kept to its simplest terms. An object type (termed a "class" in other object-oriented languages) is introduced with the <code>OBJECT</code> declaration, which has essentially the same syntax as a <code>RECORD</code> declaration, although an object type is a reference type, whereas RECORDs in Modula-3 are not (similar to structs in C). Exported types are usually named T by convention, and create a separate "Public" type to expose the methods and data. For example: <syntaxhighlight lang="modula2" highlight="1"> INTERFACE Person; TYPE T <: Public; Public = OBJECT METHODS getAge(): INTEGER; init(name: TEXT; age: INTEGER): T; END; END Person. </syntaxhighlight> This defines an interface <code>Person</code> with two types, <code>T</code>, and <code>Public</code>, which is defined as an object with two methods, <code>getAge()</code> and <code>init()</code>. <code>T</code> is defined as a subtype of <code>Public</code> by the use of the <code><:</code> operator. To create a new <code>Person.T</code> object, use the built in procedure <code>NEW</code> with the method <code>init()</code> as <syntaxhighlight lang="modula2"> VAR jim := NEW(Person.T).init("Jim", 25); </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)