This article may require cleanup to meet Wikipedia's quality standards. The specific problem is: This article's reference section contains many footnotes, but lists no external references or sources. (June 2013) |
This comparison of programming languages compares how object-oriented programming languages such as C++, Java, Smalltalk, Object Pascal, Perl, Python, and others manipulate data structures.
construction | destruction | |
---|---|---|
ABAP Objects | data variable type ref to class . [1] |
[2][3] |
APL (Dyalog) | variable←⎕NEW class «parameters»
|
⎕EX 'variable'
|
C++ (STL) | class variable«(parameters)»; orclass *variable = new class«(parameters)»;
|
delete pointer;
|
C# | class variable = new class(parameters);
|
variable.Dispose(); [3] |
Java | [3] | |
D | destroy(variable);
| |
eC | class «instance handle» { «properties/data members assignments, instance method overrides» }
|
delete instance handle;
|
Objective-C (Cocoa) | class *variable = [[class alloc ] init]; or class *variable = [[class alloc ] initWithFoo:parameter «bar:parameter ...»];
|
[variable release];
|
Swift | let variable = class(parameters)
|
|
Python | variable = class(parameters)
|
del variable [3] (Normally not needed)
|
Visual Basic .NET | Dim variable As New class(parameters)
|
variable.Dispose() [3] |
Xojo | Dim variable As New class(parameters)
|
variable = Nil
|
Eiffel | create variable orcreate «{TYPE}» variable.make_foo «(parameters)» orvariable := create {TYPE} orvariable := create {TYPE}.make_foo «(parameters)»
|
[3] |
PHP | $variable = new class«(parameters)»;
|
unset($variable); [3] |
Perl 5 | «my »$variable = class->new«(parameters)»;
|
undef($variable);
|
Raku | «my »$variable = class.new«(parameters)»;
|
$variable.undefine;
|
Ruby | variable = class.new«(parameters)»
|
[3] |
Windows PowerShell | $variable = New-Object «-TypeName» class ««-ArgumentList» parameters»
|
Remove-Variable «-Name» variable
|
OCaml | let variable = new class «parameters» or let variable = object members end [4] |
[3] |
F# | let variable = «new »class(«parameters»)
| |
Smalltalk | The class is an Object. Just send a message to a class, usually #new or #new: , and many others, for example:
Point x: 10 y: 20.
Array with: -1 with: 3 with: 2.
|
|
JavaScript | var variable = new class«(parameters)» or var variable = { «key1: value1«, key2: value2 ...»»}
|
[3] |
Object Pascal (Delphi) | ClassVar := ClassType.ConstructorName(parameters);
|
ClassVar.Free;
|
Scala | val obj = new Object // no parameters
val obj = new Object(arg0, arg1, arg2...)
val obj = Object(arg0, arg1, arg2...) // case class
val obj = new Object(arg0, arg1, param1 = value1, ...) // named parameters
|
[3] |
COBOL | INVOKE class "NEW" RETURNING variable orMOVE class::"NEW" TO variable
|
|
Cobra | variable «as class» = class(parameters)
|
variable.dispose
|
ISLISP | (setq variable (create (class <some-class> [:field-1 value-1 [:field-2 value-2] ..])))
|
[3] |
class | protocol | namespace | |
---|---|---|---|
ABAP Objects | class name definition «inheriting from parentclass». «interfaces: interfaces.» method_and_field_declarations endclass.
|
interface name. members endinterface.
|
N/A |
APL (Dyalog) | :Class name «:parentclass» «,interfaces» members :EndClass
|
:Interface name members :EndInterface
|
:Namespace name members :EndNamespace
|
C++ (STL) | class name« : public parentclasses [5]» { members };
|
namespace name { members }
| |
C# | class name« : «parentclass»«, interfaces»» { members }
|
interface name« : parentinterfaces» { members }
| |
D | module name;
| ||
eC | class name« : base class» { «default member values assignments» «members» }
|
|
namespace name;
|
Java | class name« extends parentclass»« implements interfaces» { members }
|
interface name« extends parentinterfaces» { members }
|
package name; members
|
PHP | namespace name; members
| ||
Objective-C | @interface name« : parentclass» [6]«< protocols >» { instance_fields } method_and_property_declarations @end [7] |
@protocol name«< parentprotocols >» members @end
|
[8] |
Swift | class name« : «parentclass»«, protocols»» { members }
|
protocol name« : parentprotocols» { members }
|
|
Python | class name«(parentclasses[5])»:
|
[9] | __all__ = [ member1,member2,... ]
|
Visual Basic .NET | Class name« Inherits parentclass»« Implements interfaces»
|
Interface name« Inherits parentinterfaces»
|
Namespace name
|
Xojo | Class name« Inherits parentclass»« Implements interfaces»
|
Interface name« Inherits parentinterfaces»
|
Module name
|
Eiffel | class name« inherit parentclasses[5]»
|
N/A | |
Perl | package name; «@ISA = qw(parentclasses[5]);» members 1;
|
package name; members
| |
Raku | class name «is parentclass «is parentclass ...[5]»» «does role «does role ...»» { members }
|
role name «does role «does role ...»» { members }
|
module name { members }
|
Ruby | class name« < parentclass»
|
module name
| |
Windows PowerShell | N/A | ||
OCaml | class name «parameters» = object «(self)» «inherit parentclass «parameters» «inherit parentclass «parameters» ...[5]»» members end
|
module name
| |
F# | type name«(parameters)» «as this» = class «inherit parentclass«(parameters)» «as base»» members «interface interface with implementation «interface interface with implementation ...»» end
|
type name = interface members end
|
namespace name
|
Smalltalk | [10] | [11] | |
JavaScript (ES6) | class name «extends parentclass» { members }
|
||
Object Pascal (Delphi) |
|
package name; members
| |
Scala | class ConcreteClass(constructor params)
extends ParentClass
with Trait1 with Trait2 with Trait2 {
// members
}
|
trait TraitName
extends OtherTrait1
with OtherTrait2 with OtherTrait3 {
// members
}
|
package name
|
COBOL | CLASS-ID. name« INHERITS« FROM» parentclasses».
FACTORY« IMPLEMENTS interfaces». class-members END FACTORY. OBJECT« IMPLEMENTS interfaces». instance-members END OBJECT.
|
INTERFACE-ID. name« INHERITS« FROM» interfaces».
members
|
N/A |
Cobra | class name «inherits parentclass» «implements interfaces»
|
interface name «inherits parentinterfaces»
|
namespace name
|
ISLISP | (defclass name (base-class) ((x :initform 0 :accessor get-x :initarg x)) (:abstractp nil))
|
constructor | destructor | finalizer[12] | |
---|---|---|---|
ABAP Objects | methods constructor «importing parameter = argument» [13] |
N/A | |
APL (Dyalog) | ∇ name :Implements Constructor «:Base «expr»» instructions ∇
|
∇ name :Implements Destructor instructions ∇
| |
C++ (STL) | class(«parameters») «: initializers [14]» { instructions }
|
~class() { instructions }
|
|
C# | class(«parameters») { instructions }
|
void Dispose(){ instructions }
|
~class() { instructions }
|
D | this(«parameters») { instructions }
|
~this() { instructions }
| |
eC | class() { instructions }
|
~class() { instructions }
|
|
Java | class(«parameters») { instructions }
|
void finalize() { instructions }
| |
Eiffel | [15] | [16] | |
Objective-C (Cocoa) | - (id)init { instructions... return self; } or
|
- (void)dealloc { instructions }
|
- (void)finalize { instructions }
|
Swift | init(«parameters») { instructions }
|
deinit { instructions }
|
|
Python | def __init__(self«, parameters»):
|
def __del__(self):
| |
Visual Basic .NET | Sub New(«parameters»)
|
Sub Dispose()
|
Overrides Sub Finalize()
|
Xojo | Sub Constructor(«parameters»)
|
Sub Destructor()
|
|
PHP | function __construct(«parameters») { instructions }
|
function __destruct() { instructions }
|
|
Perl | sub new { my ($class«, parameters») = @_; my $self = {}; instructions ... bless($self, $class); return $self; }
|
sub DESTROY { my ($self) = @_; instructions }
|
|
Raku | submethod BUILD { instructions } or
|
submethod DESTROY { instructions }
|
|
Ruby | def initialize«(parameters)»
|
N/A | |
Windows PowerShell | N/A | ||
OCaml | initializer instructions [17] |
N/A | |
F# | do instructions or [18] |
member this.Dispose() = instructions
|
override this.Finalize() = instructions
|
JavaScript | function name(«parameters») { instructions } [19] |
N/A | |
JavaScript (ES6) | constructor( «parameters») { instructions }
| ||
COBOL | N/A[20] | N/A | |
Cobra | cue init(parameters)
|
def dispose
|
|
ISLISP | (defmethod initialize-object ((instance <class-name>) initvalues)
|
public | private | protected | friend | |
---|---|---|---|---|
ABAP Objects | public section.[21] data field type type.
|
private section.[21] data field type type.
|
protected section.[21] data field type type.
|
[22] |
APL (Dyalog) | :Field Public field «← value»
|
:Field «Private» field «← value»
|
||
C++ (STL) | public: type field;
|
private: type field;
|
protected: type field;
|
[23] |
C# | public type field «= value»;
|
private type field «= value»;
|
protected type field «= value»;
|
internal type field «= value»;
|
D | package type field «= value»;
| |||
Java | protected type field «= value»;
|
type field «= value»;
| ||
eC | public type field;
|
private type field;
| ||
Eiffel | feature
|
feature {NONE}
|
feature {current_class}
|
feature {FRIEND}
|
Objective-C | @public type field;
|
@private type field;
|
@protected type field;
|
@package type field;
|
Swift | N/A | |||
Smalltalk | N/A | [24] | N/A | |
Python | self.field = value [25] |
N/A[26] | N/A | |
Visual Basic .NET | Public field As type «= value»
|
Private field As type «= value»
|
Protected field As type «= value»
|
Friend field As type «= value»
|
Xojo | Public field As type «= value»
|
Private field As type «= value»
|
Protected field As type «= value»
|
N/A |
PHP | public $field «= value»;
|
private $field «= value»;
|
protected $field «= value»;
|
|
Perl | $self->{field} = value; [25] |
N/A | ||
Raku | has« type »$.field« is rw»
|
has« type »$!field
|
N/A | |
Ruby | N/A | @field = value [25] |
||
Windows PowerShell | Add-Member
|
N/A | ||
OCaml | N/A | val «mutable» field = value
|
N/A | |
F# | N/A | let «mutable» field = value
|
N/A | |
JavaScript | this.field = value [25] |
|||
COBOL | N/A | level-number field clauses.[27] | N/A | N/A |
Cobra | var field «as type» «= value»
|
var __field «as type» «= value»
|
var _field «as type» «= value»
|
|
ISLISP | (field :initform value :accessor accessor-name :initarg keyword)
|
basic/void method | value-returning method | ||
---|---|---|---|
ABAP Objects | methods name «importing parameter = argument» «exporting parameter = argument» «changing parameter = argument» «returning value(parameter)» [28] |
[29] | |
APL (Dyalog) | ∇ «left argument» name «right arguments» instructions ∇
|
∇ result ← «left argument» name «right arguments» instructions ∇
| |
C++[30]
The implementation of methods is usually provided in a separate source file, with the following syntax
|
void foo(«parameters») { instructions }
|
type foo(«parameters») { instructions ... return value; }
| |
C# | |||
D | |||
Java | |||
eC | void ««type of 'this'»::»foo(«parameters») { instructions }
|
type ««type of this»::»foo(«parameters») { instructions ... return value; }
| |
Eiffel | foo ( «parameters» )
|
foo ( «parameters» ): TYPE
| |
Objective-C | - (void)foo«:parameter «bar:parameter ...»» { instructions }
|
- (type)foo«:parameter «bar:parameter ...»» { instructions... return value; }
| |
Swift | func foo(«parameters») { instructions }
|
func foo(«parameters») -> type { instructions... return value }
| |
Python | def foo(self«, parameters»):
|
def foo(self«, parameters»):
| |
Visual Basic .NET | Sub Foo(«parameters»)
|
Function Foo(«parameters») As type
| |
Xojo | Sub Foo(«parameters»)
|
Function Foo(«parameters») As type
| |
PHP | function foo(«parameters»)«: void» { instructions }
|
function foo(«parameters»)«: type» { instructions ... return value; }
| |
Perl | sub foo { my ($self«, parameters») = @_; instructions }
|
sub foo { my ($self«, parameters») = @_; instructions ... return value; }
| |
Raku | «has »«multi »method foo(««$self: »parameters») { instructions }
|
«has «type »»«multi »method foo(««$self: »parameters») { instructions ... return value; }
| |
Ruby | def foo«(parameters)»
|
def foo«(parameters)»
| |
Windows PowerShell | Add-Member «-MemberType» ScriptMethod «-Name» foo «-Value» { «param(parameters)» instructions } -InputObject variable
|
Add-Member «-MemberType» ScriptMethod «-Name» foo «-Value» { «param(parameters)» instructions ... return value } -InputObject variable
| |
OCaml | N/A | method foo «parameters» = expression
| |
F# | member this.foo(«parameters») = expression
| ||
JavaScript | this.method = function(«parameters») {instructions} [32] |
this.method = function(«parameters») {instructions... return value;} [32] | |
Javascript (ES6) | foo(«parameters») {instructions}
|
foo(«parameters») {instructions... return value;}
| |
COBOL | METHOD-ID. foo.
instructions
|
METHOD-ID. foo.
instructions
| |
Cobra | def foo(parameters)
|
def foo(parameters) as type
|
|
ISLISP | (defgeneric method (arg1 arg2))
|
How to declare a property named "Bar"
read-write | read-only | write-only | |
---|---|---|---|
ABAP Objects | N/A | ||
APL (Dyalog) | :Property Bar ∇ result ← Get instructions ∇ ∇ Set arguments instructions ∇ :EndProperty Bar
|
:Property Bar ∇ result ← Get instructions ∇ :EndProperty Bar
|
:Property Bar ∇ Set arguments instructions ∇ :EndProperty Bar
|
C++ (STL) | N/A | ||
C# | type Bar {
|
type Bar { get { instructions ... return value; } }
|
type Bar { set { instructions } }
|
D | @property type bar() { instructions ... return value; }
|
@property type bar() { instructions ... return value; }
|
@property type bar(type value) { instructions ... return value; }
|
eC | property type Bar {
|
property type Bar { get { instructions ... return value; } }
|
property type Bar { set { instructions } }
|
Java | N/A | ||
Objective-C 2.0 (Cocoa) | @property (readwrite) type bar; and then inside @implementation
|
@property (readonly) type bar; and then inside @implementation
|
N/A |
Swift | var bar : type { get { instructions } set«(newBar)» { instructions } }
|
var bar : type { instructions }
|
N/A |
Eiffel | feature -- Access
|
||
Python | def setBar(self, value): [33] |
def getBar(self):
|
def setBar(self, value):
|
Visual Basic .NET | Property Bar() As type
|
ReadOnly Property Bar() As type
|
WriteOnly Property Bar() As type
|
Xojo | ComputedProperty Bar() As type
|
ComputedProperty Bar() As type
|
ComputedProperty Bar() As type
|
PHP | function __get($property) {
|
function __get($property) {
|
function __set($property, $value) {
|
Perl | sub Bar {
|
sub Bar {
|
sub Bar {
|
Raku | N/A | ||
Ruby | def bar
|
def bar
|
def bar=(value)
|
Windows PowerShell | Add-Member
|
Add-Member
|
Add-Member
|
OCaml | N/A | ||
F# | member this.Bar with get() = expression and set(value) = expression
|
member this.Bar = expression
|
member this.Bar with set(value) = expression
|
JavaScript (ES6) | get bar(«parameters») { instructions ... return value}set bar(«parameters») { instructions }
|
get bar(«parameters») { instructions ... return value}
|
set bar(«parameters») { instructions }
|
COBOL | METHOD-ID. GET PROPERTY bar.
instructions
instructions
|
METHOD-ID. GET PROPERTY bar.
instructions
|
METHOD-ID. SET PROPERTY bar.
instructions
|
Cobra | pro bar «as type»
|
get bar «as type»
|
set bar «as type»
|
ISLISP | N/A |
read-write | read-only | write-only | |
---|---|---|---|
ABAP Objects | N/A | ||
C++ (STL) | N/A | ||
C# | type Bar { get; set; }
|
type Bar { get; private set; }
|
type Bar { private get; set; }
|
D | N/A | ||
Java | N/A | ||
Objective-C 2.0 (Cocoa) | @property (readwrite) type bar; and then inside @implementation
|
@property (readonly) type bar; and then inside @implementation
|
N/A |
Swift | var bar : type
|
let bar : type
|
N/A |
Eiffel | |||
Python | @property
|
@property
|
bar = property()
|
Visual Basic .NET | Property Bar As type« = initial_value» (VB 10)
|
||
PHP | |||
Perl[34] | use base qw(Class::Accessor);
|
use base qw(Class::Accessor);
|
use base qw(Class::Accessor);
|
Raku | N/A | ||
Ruby | attr_accessor :bar
|
attr_reader :bar
|
attr_writer :bar
|
Windows PowerShell | |||
OCaml | N/A | ||
F# | member val Bar = value with get, set
|
||
COBOL | level-number bar clauses PROPERTY.
|
level-number bar clauses PROPERTY «WITH» NO SET.
|
level-number bar clauses PROPERTY «WITH» NO GET.
|
Cobra | pro bar from var «as type»
|
get bar from var «as type»
|
set bar from var «as type»
|
unary | binary | function call | |
---|---|---|---|
ABAP Objects | N/A | ||
C++ (STL) | type operator symbol () { instructions }
|
type operator symbol (type operand2) { instructions }
|
type operator () («parameters») { instructions }
|
C# | static type operator symbol(type operand) { instructions }
|
static type operator symbol(type operand1, type operand2) { instructions }
|
N/A |
D | type opUnary(string s)() if (s == "symbol") { instructions }
|
type opBinary(string s)(type operand2) if (s == "symbol") { instructions }
|
type opCall(«parameters») { instructions }
|
Java | N/A | ||
Objective-C | |||
Swift | func symbol(operand1 : type) -> returntype { instructions } (outside class)
|
func symbol(operand1 : type1, operand2 : type2) -> returntype { instructions } (outside class)
|
|
Eiffel[35] | op_name alias "symbol": TYPE
|
op_name alias "symbol" (operand: TYPE1): TYPE2
|
|
Python | def __opname__(self):
|
def __opname__(self, operand2):
|
def __call__(self«, parameters»):
|
Visual Basic .NET | Shared Operator symbol(operand As type) As type
|
Shared Operator symbol(operand1 As type, operand2 As type) As type
|
N/A |
Xojo | Function Operator_name(operand As type) As type
|
N/A | |
PHP | [36] | function __invoke(«parameters») { instructions } (PHP 5.3+)
| |
Perl | use overload "symbol" => sub { my ($self) = @_; instructions };
|
use overload "symbol" => sub { my ($self, $operand2, $operands_reversed) = @_; instructions };
|
|
Raku | «our «type »»«multi »method prefix:<symbol> («$operand: ») { instructions ... return value; } or
|
«our «type »»«multi »method infix:<symbol> («$operand1: » type operand2) { instructions ... return value; }
|
«our «type »»«multi »method postcircumfix:<( )> («$self: » «parameters») { instructions }
|
Ruby | def symbol
|
def symbol(operand2)
|
N/A |
Windows PowerShell | N/A | ||
OCaml | |||
F# | static member (symbol) operand = expression
|
static member (symbol) (operand1, operand2) = expression
|
N/A |
COBOL | N/A | ||
ISLISP | N/A |
read-write | read-only | write-only | |
---|---|---|---|
ABAP Objects | N/A | ||
APL (Dyalog) | :Property Numbered Default name ∇ result ← Get instructions ∇ ∇ Set arguments instructions ∇ :EndProperty Bar
|
:Property Numbered Default Bar ∇ result ← Get instructions ∇ :EndProperty Bar
|
:Property Numbered Default Bar ∇ Set arguments instructions ∇ :EndProperty Bar
|
C++ (STL) | type& operator[](type index) { instructions }
|
type operator[](type index) { instructions }
|
|
C# | type this[type index] {
|
type this[type index] { get{ instructions } }
|
type this[type index] { set{ instructions } }
|
D | type opIndex(type index) { instructions }
|
type opIndex(type index) { instructions }
|
type opIndexAssign(type value, type index) { instructions }
|
Java | N/A | ||
Objective-C (recent Clang compiler) | N/A | - (id)objectAtIndexedSubscript:(NSUInteger)index { instructions return value; } or
|
- (void)setObject:(id)value atIndexedSubscript:(NSUInteger)index { instructions } or
|
Swift | subscript (index : type) -> returntype { get { instructions } set«(newIndex)» { instructions } }
|
subscript (index : type) -> returntype { instructions }
|
|
Eiffel[35] | bracket_name alias "[]" (index: TYPE): TYPE assign set_item
|
bracket_name alias "[]" (index: TYPE): TYPE
|
|
Python | def __getitem__(self, index):
|
def __getitem__(self, index):
|
def __setitem__(self, index, value):
|
Visual Basic .NET | Default Property Item(Index As type) As type
|
Default ReadOnly Property Item(Index As type) As type
|
Default WriteOnly Property Item(Index As type) As type
|
PHP | [37] | ||
Perl | [38] | ||
Raku | «our «type »»«multi »method postcircumfix:<[ ]> is rw («$self: » type $index) { instructions ... return value; } or
|
«our «type »»«multi »method postcircumfix:<[ ]>(«$self: » type $index) { instructions ... return value; } or
|
N/A |
Ruby | def [](index)
|
def [](index)
|
def []=(index, value)
|
Windows PowerShell | N/A | ||
OCaml | |||
F# | member this.Item with get(index) = expression and set index value = expression
|
member this.Item with get(index) = expression
|
member this.Item with set index value = expression
|
COBOL | N/A | ||
Cobra | pro[index «as type»] as type
|
get[index «as type»] as type
|
set[index «as type»] as type
|
downcast | upcast | |
---|---|---|
ABAP Objects | N/A | |
C++ (STL) | operator returntype() { instructions }
| |
C# | static explicit operator returntype(type operand) { instructions }
|
static implicit operator returntype(type operand) { instructions }
|
D | T opCast(T)() if (is(T == type)) { instructions }
| |
eC | property T { get { return «conversion code»; } }
| |
Java | N/A | |
Objective-C | ||
Eiffel[35] | ||
Python | ||
Visual Basic .NET | Shared Narrowing Operator CType(operand As type) As returntype
|
Shared Widening Operator CType(operand As type) As returntype
|
PHP | N/A | |
Perl | ||
Raku | multi method type«($self:)» is export { instructions }
| |
Ruby | N/A | |
Windows PowerShell | ||
OCaml | ||
F# | ||
COBOL | N/A |
How to access members of an object x
object member | class member | namespace member | |||
---|---|---|---|---|---|
method | field | property | |||
ABAP Objects | x->method(«parameters»). [39] |
x->field
|
N/A | x=>field or x=>method(«parameters[39]»).
|
N/A |
C++ (STL) | x.method(parameters) or
|
x.field or
|
cls::member
|
ns::member
| |
Objective-C | [x method«:parameter «bar:parameter ...»»]
|
x->field
|
x.property (2.0 only) or
|
[cls method«:parameter «bar:parameter ...»»]
|
|
Smalltalk | x method«:parameter «bar:parameter ...»»
|
N/A | cls method«:parameter «bar:parameter ...»»
|
||
Swift | x.method(parameters)
|
x.property
|
cls.member
|
||
APL (Dyalog) | left argument» x.method «right argument(s)»
|
x.field
|
x.property
|
cls.member
|
ns.member
|
C# | x.method(parameters)
| ||||
Java | N/A | ||||
D | x.property
| ||||
Python | |||||
Visual Basic .NET | |||||
Xojo | |||||
Windows PowerShell | [cls]::member
| ||||
F# | N/A | cls.member
| |||
eC | x.method«(parameters)»
|
x.field
|
x.property
|
cls::member
|
ns::member
|
Eiffel | x.method«(parameters)»
|
x.field
|
{cls}.member
|
N/A | |
Ruby | N/A | x.property
|
cls.member
| ||
PHP | x->method(parameters)
|
x->field
|
x->property
|
cls::member
|
ns\member
|
Perl | x->method«(parameters)»
|
x->{field}
|
cls->method«(parameters)»
|
ns::member
| |
Raku | x.method«(parameters)» or
|
x.field or
|
cls.method«(parameters)» or
|
ns::member
| |
OCaml | x#method «parameters»
|
N/A | |||
JavaScript | x.method(parameters)
|
x.field
|
x.property
|
cls.member
|
N/A |
COBOL | INVOKE x "method" «USING parameters» «RETURNING result» or
|
N/A | property OF x
|
INVOKE cls "method" «USING parameters» «RETURNING result» or
|
N/A |
Cobra | x.method«(parameters)»
|
x.field
|
x.property
|
cls.member
|
ns.member
|
Has member? | Handler for missing member | |||
---|---|---|---|---|
Method | Field | Method | Field | |
APL (Dyalog) | 3=x.⎕NC'method'
|
2=x.⎕NC'method'
|
N/A | |
ABAP Objects | N/A | |||
C++ (STL) | ||||
Objective-C (Cocoa) | [x respondsToSelector:@selector(method)]
|
N/A | forwardInvocation:
|
N/A |
Smalltalk | x respondsTo: selector
|
N/A | doesNotUnderstand:
|
N/A |
C# | (using reflection) | |||
eC | ||||
Java | ||||
D | opDispatch()
| |||
Eiffel | N/A | |||
Python | hasattr(x, "method") and callable(x.method)
|
hasattr(x, "field")
|
__getattr__()
| |
Visual Basic .NET | (using reflection) | |||
Xojo | (using Introspection) | |||
Windows PowerShell | (using reflection) | |||
F# | (using reflection) | |||
Ruby | x.respond_to?(:method)
|
N/A | method_missing()
|
N/A |
PHP | method_exists(x, "method")
|
property_exists(x, "field")
|
__call()
|
__get() / __set()
|
Perl | x->can("method")
|
exists x->{field}
|
AUTOLOAD | |
Raku | x.can("method")
|
x.field.defined
|
AUTOLOAD | |
OCaml | N/A | |||
JavaScript | typeof x.method === "function"
|
field in x
|
||
COBOL | N/A |
current object | current object's parent object | null reference | Current Context of Execution | |
---|---|---|---|---|
Smalltalk | self
|
super
|
nil
|
thisContext
|
ABAP Objects | me
|
super
|
initial
|
|
APL (Dyalog) | ⎕THIS
|
⎕BASE
|
⎕NULL
|
|
C++ (STL) | *this
|
[40] | NULL, nullptr
|
|
C# | this
|
base [41] |
null
|
|
Java | super [41] |
|||
D | ||||
JavaScript | super [41] (ECMAScript 6)
|
null, undefined [42] |
||
eC | this
|
null
|
||
Objective-C | self
|
super [41] |
nil
|
|
Swift | self
|
super [41] |
nil [43] |
|
Python | self [44] |
super(current_class_name, self) [5]super() (3.x only)
|
None
|
|
Visual Basic .NET | Me
|
MyBase
|
Nothing
|
|
Xojo | Me / Self
|
Parent
|
Nil
|
|
Eiffel | Current
|
Precursor «{superclass}» «(args)» [41][45] |
Void
|
|
PHP | $this
|
parent [41] |
null
|
|
Perl | $self [44] |
$self->SUPER [41] |
undef
|
|
Raku | self
|
SUPER
|
Nil
|
|
Ruby | self
|
super«(args)» [46] |
nil
|
binding
|
Windows PowerShell | $this
|
$NULL
|
||
OCaml | self [47] |
super [48] |
N/A[49] | |
F# | this
|
base [41] |
null
|
|
COBOL | SELF
|
SUPER
|
NULL
|
|
Cobra | this
|
base
|
nil
|
String representation | Object copy | Value equality | Object comparison | Hash code | Object ID | ||
---|---|---|---|---|---|---|---|
Human-readable | Source-compatible | ||||||
ABAP Objects | N/A | ||||||
APL (Dyalog) | ⍕x
|
⎕SRC x
|
⎕NS x
|
x = y
|
N/A | ||
C++ (STL) | x == y [50] |
pointer to object can be converted into an integer ID | |||||
C# | x.ToString()
|
x.Clone()
|
x.Equals(y)
|
x.CompareTo(y)
|
x.GetHashCode()
|
System
| |
Java | x.toString()
|
x.clone() [51] |
x.equals(y)
|
x.compareTo(y) [52] |
x.hashCode()
|
System
| |
JavaScript | x.toString()
|
||||||
D | x.toString() or
|
x.stringof
|
x == y or
|
x.opCmp(y)
|
x.toHash()
|
||
eC | x.OnGetString(tempString, null, null) or
|
y.OnCopy(x)
|
x.OnCompare(y)
|
object handle can be converted into an integer ID | |||
Objective-C (Cocoa) | x.description
|
x.debugDescription
|
[x copy] [53] |
[x isEqual:y]
|
[x compare:y] [54] |
x.hash
|
pointer to object can be converted into an integer ID |
Swift | x.description [55] |
x.debugDescription [56] |
x == y [57] |
x < y [58] |
x.hashValue [59] |
reflect(x)
| |
Smalltalk | x displayString
|
x printString
|
x copy
|
x = y
|
x hash
|
x identityHash
| |
Python | str(x) [60] |
repr(x) [61] |
copy.copy(x) [62] |
x == y [63] |
cmp(x, y) [64] |
hash(x) [65] |
id(x)
|
Visual Basic .NET | x.ToString()
|
x.Clone()
|
x.Equals(y)
|
x.CompareTo(y)
|
x.GetHashCode()
|
||
Eiffel | x.out
|
x.twin
|
x.is_equal(y)
|
When x is COMPARABLE , one can simply do x < y
|
When x is HASHABLE , one can use x.hash_code
|
When x is IDENTIFIED , one can use x.object_id
| |
PHP | $x->__toString()
|
clone x [66] |
x == y
|
|
spl_object_hash(x)
| ||
Perl | "$x" [67] |
Data::Dumper [68] |
Storable [69] |
Scalar [70] | |||
Raku | ~x [67] |
x.perl
|
x.clone
|
x eqv y
|
x cmp y
|
x.WHICH
| |
Ruby | x.to_s
|
x.inspect
|
x.dup or
|
x == y or
|
x <=> y
|
x.hash
|
x.object_id
|
Windows PowerShell | x.ToString()
|
x.Clone()
|
x.Equals(y)
|
x.CompareTo(y)
|
x.GetHashCode()
|
||
OCaml | Oo.copy x
|
x = y
|
Hashtbl
|
Oo.id x
| |||
F# | string x or x
|
sprintf "%A" x
|
x.Clone()
|
x = y or x
|
compare x y or x
|
hash x or x
|
|
COBOL | N/A |
Get object type | Is instance of (includes subtypes) | Upcasting | Downcasting | ||
---|---|---|---|---|---|
Runtime check | No check | ||||
ABAP Objects | N/A[71] | = | ?= | ||
C++ (STL) | typeid(x)
|
dynamic_cast<type *>(&x) != nullptr
|
N/A[72] | dynamic_cast<type*>(ptr)
|
(type*) ptr or
|
C# | x.GetType()
|
x is type
|
(type) x or x as type
|
||
D | typeid(x)
|
cast(type) x
|
|||
Delphi | x is type
|
x as type
|
|||
eC | x._class
|
eClass_IsDerived(x._class, type)
|
(type) x
| ||
Java | x.getClass()
|
x instanceof class
|
(type) x
|
||
Objective-C (Cocoa) | [x class] [73] |
[x isKindOfClass:[class class]]
|
(type*) x
| ||
Swift | x.dynamicType
|
x is type
|
x as! type x as? type
| ||
JavaScript | x.constructor (If not rewritten.)
|
x instanceof class
|
N/A[74] | ||
Visual Basic .NET | x.GetType()
|
TypeOf x Is type
|
N/A[72] | CType(x, type) or TryCast(x, type)
|
|
Xojo | Introspection.GetType(x)
|
x IsA type
|
N/A | CType(x, type)
|
N/A |
Eiffel | x.generating_type
|
attached {TYPE} x
|
attached {TYPE} x as down_x
|
||
Python | type(x)
|
isinstance(x, type)
|
N/A[74] | ||
PHP | get_class(x)
|
x instanceof class
| |||
Perl | ref(x)
|
x->isa("class")
| |||
Raku | x.WHAT
|
x.isa(class)
|
N/A[72] | type(x) or
|
|
Ruby | x.class
|
x.instance_of?(type) or
|
N/A[74] | ||
Smalltalk | x class
|
x isKindOf: class
| |||
Windows PowerShell | x.GetType()
|
x -is [type]
|
N/A[72] | [type]x or x -as [type]
|
|
OCaml | N/A[75] | (x :> type)
|
N/A | ||
F# | x.GetType()
|
x :? type
|
(x :?> type)
|
||
COBOL | N/A | x AS type [72] |
N/A |
Import namespace | Import item | ||
---|---|---|---|
qualified | unqualified | ||
ABAP Objects | |||
C++ (STL) | using namespace ns;
|
using ns::item ;
| |
C# | using ns;
|
using item = ns.item;
| |
D | import ns;
|
import ns : item;
| |
Java | import ns.*;
|
import ns.item;
| |
Objective-C | |||
Visual Basic .NET | Imports ns
|
||
Eiffel | |||
Python | import ns
|
from ns import *
|
from ns import item
|
PHP | use ns;
|
use ns\item;
| |
Perl | use ns;
|
use ns qw(item);
| |
Raku | |||
Ruby | |||
Windows PowerShell | |||
OCaml | open ns
|
||
F# | |||
COBOL | N/A |
Precondition | Postcondition | Check | Invariant | Loop | |
---|---|---|---|---|---|
ABAP Objects | N/A | ||||
C++ (STL) | |||||
C# | Spec#:
|
Spec#:
| |||
Java | N/A | ||||
Objective-C | |||||
Visual Basic .NET | |||||
D | f
|
f
|
assert(expression)
|
invariant() { expression }
|
|
Eiffel | f
|
f
|
f
|
class X
|
from instructions
|
Python | N/A | ||||
PHP | |||||
Perl | |||||
Raku | PRE { condition }
|
POST { condition }
|
|||
Ruby | N/A | ||||
Windows PowerShell | |||||
OCaml | |||||
F# | |||||
COBOL |
NSObject
for Cocoa and GNUstep, or Object
otherwise.
@interface
portion is placed into a header file, and the @interface
portion is placed into a separate source code file.
"member_name(parameters)"
"class_name(parameters)".
class addInstVarName: field.
class removeInstVarName: field.
def bar():
doc = "The bar property."
def fget(self):
return self._bar
def fset(self, value):
self._bar = value
return locals()
bar = property(**bar())
x->method(«exporting parameter = argument» «importing parameter = argument» «changing parameter = argument» «returning value(parameter)»
parameter = argument
can be repeated if there are several parametersBaseClassName::member
syntax can be used to access an overridden member in the specified base class. Microsoft Visual C++ provides a non-standard keyword "__super" for this purpose; but this is unsupported in other compilers.[1]
option
type, which values are None
and Some x
, which could be used to represent "null reference" and "non-null reference to an object" as in other languages.
==
operator
clone()
method inherited from Object
is protected, unless the class overrides the method and makes it public. If using the clone()
inherited from Object
, the class must implement the Cloneable
interface to allow cloning.
Comparable
for this method to be standardized.
copyWithZone:
method
compare:
is the conventional name for the comparison method in Foundation classes. However, no formal protocol exists
Printable
protocol
DebugPrintable
protocol
Equatable
protocol
Comparable
protocol
hashValue
protocol
__str__()
method
__repr__()
method
__copy__()
method
__eq__()
method
__cmp__()
method
__hash__()
method. Not all types are hashable (mutable types are usually not hashable)
__clone()
method
x
is a class object, [x class]
returns only x
. The runtime method object_getClass(x)
will return the class of x
for all objects.
By: Wikipedia.org
Edited: 2021-06-18 19:25:08
Source: Wikipedia.org