fbpx
Wikipedia

Comparison of programming languages (object-oriented programming)

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.

Object construction and destruction edit

construction destruction
ABAP Objects data variable type ref to class .
create object variable «exporting parameter = argument».
[1]
[2][3]
APL (Dyalog) variable←⎕NEW class «parameters» ⎕EX 'variable'
C++ class variable«(parameters)»;[4] or
class *variable = new class«(parameters)»;[5]
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 or
create «{TYPE}» variable.make_foo «(parameters)» or
variable := create {TYPE} or
variable := 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[6]
[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 or
MOVE 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 declaration edit

class protocol namespace
ABAP Objects class name definition «inheriting from parentclass». «interfaces: interfaces.» method_and_field_declarations endclass.
class name implementation. method_implementations endclass.
interface name. members endinterface.
APL (Dyalog) :Class name «:parentclass» «,interfaces»
members
:EndClass
:Interface name
members
:EndInterface
:Namespace name
members
:EndNamespace
C++ class name« : public parentclasses[7]» { members }; namespace name { members }
C# class name« : «parentclass»«, interfaces»» { members } interface name« : parentinterfaces» { members }
D module name;
members
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»[8]«< protocols >» { instance_fields } method_and_property_declarations @end
@implementation
name method_implementations @end
[9]
@protocol name«< parentprotocols >» members @end [10]
Swift class name« : «parentclass»«, protocols»» { members } protocol name« : parentprotocols» { members }
Python class name«(parentclasses[7])»:
Tab ↹
members
[11] __all__ = [ member1,member2,... ]
Visual Basic .NET Class name« Inherits parentclass»« Implements interfaces»
members
End Class
Interface name« Inherits parentinterfaces»
members
End Interface
Namespace name
members
End Namespace
Xojo Class name« Inherits parentclass»« Implements interfaces»
members
End Class
Interface name« Inherits parentinterfaces»
members
End Interface
Module name
members
End Module
Eiffel class name« inherit parentclasses[7]»
members
end
Perl package name; «@ISA = qw(parentclasses[7]);» members 1; package name; members
Raku class name «is parentclass «is parentclass ...[7]»» «does role «does role ...»» { members } role name «does role «does role ...»» { members } module name { members }
Ruby class name« < parentclass»
members
end
module name
members
end
Windows PowerShell
OCaml class name «parameters» = object «(self)» «inherit parentclass «parameters» «inherit parentclass «parameters» ...[7]»» members end module name
members
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
members
Smalltalk [12] [13]
JavaScript (ES6) class name «extends parentclass» { members }
Object Pascal (Delphi)

ClassName = Class «(ClassParent, Interfaces)»
private
// Private members(include Methods and Fields)
public
// Public members
protected
// Protected members
published
// Published members
end;

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.

END CLASS name.

INTERFACE-ID. name« INHERITS« FROM» interfaces».
    members

END INTERFACE name.

Cobra class name «inherits parentclass» «implements interfaces»
Tab ↹ members
interface name «inherits parentinterfaces»
Tab ↹ members
namespace name
Tab ↹ members
ISLISP (defclass name (base-class) ((x :initform 0 :accessor get-x :initarg x)) (:abstractp nil))

Class members edit

Constructors and destructors edit

constructor destructor finalizer[14]
ABAP Objects methods constructor «importing parameter = argument»
method constructor. instructions endmethod.
[15]
APL (Dyalog) name
:Implements Constructor «:Base «expr»»
instructions
name
:Implements Destructor
instructions
C++ class(«parameters») «: initializers[16]» { 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 [17] [18]
Objective-C (Cocoa) - (id)init { instructions... return self; } or
- (id)initWithFoo:parameter «bar:parameter ...» { instructions... return self; }
- (void)dealloc { instructions } - (void)finalize { instructions }
Swift init(«parameters») { instructions } deinit { instructions }
Python def __init__(self«, parameters»):
Tab ↹ instructions
def __del__(self):
Tab ↹ instructions
Visual Basic .NET Sub New(«parameters»)
instructions
End Sub
Sub Dispose()
instructions
End Sub
Overrides Sub Finalize()
instructions
End Sub
Xojo Sub Constructor(«parameters»)
instructions
End Sub
Sub Destructor()
instructions
End Sub
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
«multi » method new(««$self: »parameters») { self.bless(*, field1 => value1, ...); ... instructions }
submethod DESTROY { instructions }
Ruby def initialize«(parameters)»
instructions
end
Windows PowerShell
OCaml initializer instructions[19]
F# do instructions or
new(parameters) = expression
[20]
member this.Dispose() = instructions override this.Finalize() = instructions
JavaScript function name(«parameters») { instructions }[21]
JavaScript (ES6) constructor(«parameters») { instructions }
COBOL [22]
Cobra cue init(parameters)
Tab ↹ base.init
Tab ↹ instructions
def dispose
Tab ↹ instructions
ISLISP (defmethod initialize-object ((instance <class-name>) initvalues)

Fields edit

public private protected friend
ABAP Objects public section.[23] data field type type. private section.[23] data field type type. protected section.[23] data field type type. [24]
APL (Dyalog) :Field Public field « value» :Field «Private» field « value»
C++ public: type field; private: type field; protected: type field; [25]
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
field: TYPE
feature {NONE}
field: TYPE
feature {current_class}
field: TYPE
feature {FRIEND}
field: TYPE
Objective-C @public type field; @private type field; @protected type field; @package type field;
Swift
Smalltalk [26]
Python self.field = value[27] [28]
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»
PHP public $field «= value»; private $field «= value»; protected $field «= value»;
Perl $self->{field} = value;[27]
Raku has« type »$.field« is rw» has« type »$!field
Ruby @field = value[27]
Windows PowerShell Add-Member
«-MemberType »NoteProperty
«-Name »Bar «-Value »value
-InputObject variable
OCaml val «mutable» field = value
F# let «mutable» field = value
JavaScript this.field = value
this["field"] = value
[27]
COBOL level-number field clauses.[29]
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)

Methods edit

basic/void method value-returning method
ABAP Objects methods name «importing parameter = argument» «exporting parameter = argument» «changing parameter = argument» «returning value(parameter)»
method name. instructions endmethod.
[30]
[31]
APL (Dyalog) «left argument» name «right arguments»
instructions
result «left argument» name «right arguments»
instructions
C++[32]
type foo(«parameters»);

The implementation of methods is usually provided in a separate source file, with the following syntax

type class::foo(«parameters») { instructions }[33]
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» )
do
instructions
end
foo ( «parameters» ): TYPE
do
instructions...
Result := value
end
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»):
Tab ↹
instructions
def foo(self«, parameters»):
Tab ↹
instructions
Tab ↹ return
value
Visual Basic .NET Sub Foo(«parameters»)
instructions
End Sub
Function Foo(«parameters») As type
instructions
...
Return value
End Function
Xojo Sub Foo(«parameters»)
instructions
End Sub
Function Foo(«parameters») As type
instructions
...
Return value
End Function
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)»
instructions
end
def foo«(parameters)»
instructions
expression resulting in return value
end
or
def foo«(parameters
instructions
return value
end
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 method foo «parameters» = expression
F# member this.foo(«parameters») = expression
JavaScript this.method = function(«parameters») {instructions}
name«.prototype.method = function(«parameters») {instructions}
[34]
this.method = function(«parameters») {instructions... return value;}
name«.prototype.method = function(«parameters») {instructions... return value;}
[34]
Javascript (ES6) foo(«parameters») {instructions} foo(«parameters») {instructions... return value;}
COBOL METHOD-ID. foo.
«DATA DIVISION.
LINKAGE SECTION.
parameter declarations»
PROCEDURE DIVISION« USING parameters».
    instructions

END METHOD foo.

METHOD-ID. foo.
DATA DIVISION.
LINKAGE SECTION.
«parameter declarations»
result-var declaration
PROCEDURE DIVISION« USING parameters» RETURNING result-var.
    instructions

END METHOD foo.

Cobra def foo(parameters)
Tab ↹ instructions
def foo(parameters) as type
Tab ↹ instructions
Tab ↹ return value
ISLISP (defgeneric method (arg1 arg2))
(defmethod method ((arg1 <class1> arg2 <class2>) ...)

Properties edit

How to declare a property named "Bar"

Manually implemented edit

read-write read-only write-only
ABAP Objects
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++
C# type Bar {
get {
instructions ... return value; }
set {
instructions } }
type Bar { get { instructions ... return value; } } type Bar { set { instructions } }
D @property type bar() { instructions ... return value; }
@property
type bar(type value) { instructions ... return value; }
@property type bar() { instructions ... return value; } @property type bar(type value) { instructions ... return value; }
eC property type Bar {
get {
instructions ... return value; }
set {
instructions } }
property type Bar { get { instructions ... return value; } } property type Bar { set { instructions } }
Java
Objective-C 2.0 (Cocoa) @property (readwrite) type bar;
and then inside
@implementation
- (type)bar { instructions }
- (void)setBar:(type)value { instructions }
@property (readonly) type bar;
and then inside
@implementation
- (type)bar { instructions }
Swift var bar : type { get { instructions } set«(newBar)» { instructions } } var bar : type { instructions }
Eiffel feature -- Access
x: TYPE assign set_x
feature -- Settings
set_x (a_x: like x) do instructions ensure x_set: verification end
Python def setBar(self, value):
Tab ↹ instructions
def
getBar(self):
Tab ↹
instructions
Tab ↹ return value
bar = property(getBar, setBar)
[35]
def getBar(self):
Tab ↹ instructions
Tab ↹ return value
bar = property(getBar)
def setBar(self, value):
Tab ↹ instructions
bar = property(fset = setBar)
Visual Basic .NET Property Bar() As type
Get
instructions
Return value
End Get
Set (ByVal
Value As type)
instructions
End Set
End Property
ReadOnly Property Bar() As type
Get
instructions
Return value
End Get
End Property
WriteOnly Property Bar() As type
Set (ByVal Value As type)
instructions
End Set
End Property
Xojo ComputedProperty Bar() As type
Get
instructions
Return value
End Get
Set (ByVal
Value As type)
instructions
End Set
End ComputedProperty
ComputedProperty Bar() As type
Get
instructions
Return value
End Get
End ComputedProperty
ComputedProperty Bar() As type
Set (value As type)
instructions
End Set
End ComputedProperty
PHP function __get($property) {
switch (
$property) {
case
'Bar' : instructions ... return value;
} }
function __set(
$property, $value) {
switch (
$property) {
case
'Bar' : instructions
} }
function __get($property) {
switch ($
property) {
case
'Bar' : instructions ... return value;
} }
function __set($property, $value) {
switch (
$property) {
case
'Bar' : instructions
} }
Perl sub Bar {
my $self = shift;
if (my $Bar = shift) {
# setter
$self->{Bar} = $Bar;
return $self;
} else {
# getter
return $self->{Bar};
}
}
sub Bar {
my $self = shift;
if (my $Bar = shift) {
# read-only
die "Bar is read-only\n";
} else {
# getter
return $self->{Bar};
}
}
sub Bar {
my $self = shift;
if (my $Bar = shift) {
# setter
$self->{Bar} = $Bar;
return $self;
} else {
# write-only
die "Bar is write-only\n";
}
}
Raku
Ruby def bar
instructions
expression resulting in return value
end
def bar=(value)
instructions
end
def bar
instructions
expression resulting in return value
end
def bar=(value)
instructions
end
Windows PowerShell Add-Member
«-MemberType »ScriptProperty
«-Name »Bar «-Value »{ instructions ... return value }
«-SecondValue »{ instructions }
-InputObject variable
Add-Member
«-MemberType »ScriptProperty
«-Name »Bar «-Value »{ instructions ... return value}
-InputObject variable
Add-Member
«-MemberType »ScriptProperty
«-Name »Bar -SecondValue { instructions }
-InputObject variable
OCaml
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.
DATA DIVISION.
LINKAGE SECTION.
return-var declaration
PROCEDURE DIVISION RETURNING return-var.
    instructions

END METHOD.
METHOD-ID. SET PROPERTY bar.
DATA DIVISION.
LINKAGE SECTION.
value-var declaration
PROCEDURE DIVISION USING value-var.

    instructions

END METHOD.

METHOD-ID. GET PROPERTY bar.
DATA DIVISION.
LINKAGE SECTION.
return-var declaration
PROCEDURE DIVISION RETURNING return-var.
    instructions

END METHOD.

METHOD-ID. SET PROPERTY bar.
DATA DIVISION.
LINKAGE SECTION.
value-var declaration
PROCEDURE DIVISION USING value-var.
    instructions

END METHOD.

Cobra pro bar «as type»
Tab ↹ get
Tab ↹Tab ↹ instructions
Tab ↹Tab ↹ return value
Tab ↹ set
Tab ↹Tab ↹ instructions
get bar «as type»
Tab ↹ instructions
Tab ↹ return value
set bar «as type»
Tab ↹ instructions
ISLISP

Automatically implemented edit

read-write read-only write-only
ABAP Objects
C++
C# type Bar { get; set; } type Bar { get; private set; } type Bar { private get; set; }
D
Java
Objective-C 2.0 (Cocoa) @property (readwrite) type bar;
and then inside @implementation
@synthesize bar;
@property (readonly) type bar;
and then inside @implementation
@synthesize bar;
Swift var bar : type let bar : type
Eiffel
Python @property
def bar(self):
Tab ↹instructions
@bar.setter
def bar(self, value):
Tab ↹instructions
@property
def bar(self):
Tab ↹instructions
bar = property()
@bar.setter
def bar(self, value):
Tab ↹instructions
Visual Basic .NET Property Bar As type« = initial_value» (VB 10)
PHP
Perl[36] use base qw(Class::Accessor);
__PACKAGE__->mk_accessors('Bar');
use base qw(Class::Accessor);
__PACKAGE__->mk_ro_accessors('Bar');
use base qw(Class::Accessor);
__PACKAGE__->mk_wo_accessors('Bar');
Raku
Ruby attr_accessor :bar attr_reader :bar attr_writer :bar
Windows PowerShell
OCaml
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»

Overloaded operators edit

Standard operators edit

unary binary function call
ABAP Objects
C++ 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 }
D type opUnary(string s)() if (s == "symbol") { instructions } type opBinary(string s)(type operand2) if (s == "symbol") { instructions }
type opBinaryRight(string s)(type operand1) if (s == "symbol") switch (s) { instructions }
type opCall(«parameters») { instructions }
Java
Objective-C
Swift func symbol(operand1 : type) -> returntype { instructions } (outside class) func symbol(operand1 : type1, operand2 : type2) -> returntype { instructions } (outside class)
Eiffel[37] op_name alias "symbol": TYPE
do instructions end
op_name alias "symbol" (operand: TYPE1): TYPE2
do instructions end
Python def __opname__(self):
Tab ↹
instructions
Tab ↹ return
value
def __opname__(self, operand2):
Tab ↹
instructions
Tab ↹ return
value
def __call__(self«, parameters»):
Tab ↹
instructions
Tab ↹ return
value
Visual Basic .NET Shared Operator symbol(operand As type) As type
instructions
End Operator
Shared Operator symbol(operand1 As type, operand2 As type) As type
instructions
End Operator
Xojo Function Operator_name(operand As type) As type
instructions
End Function
PHP [38] 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 postfix:<symbol> («$operand: ») { instructions ... return value; } or
«our «type »»«multi »method circumfix:<symbol1 symbol2> («$operand: ») { instructions ... return value; }
«our «type »»«multi »method infix:<symbol> («$operand1: » type operand2) { instructions ... return value; } «our «type »»«multi »method postcircumfix:<( )> («$self: » «parameters») { instructions }
Ruby def symbol
instructions
expression resulting in return value
end
def symbol(operand2)
instructions
expression resulting in return value
end
Windows PowerShell
OCaml
F# static member (symbol) operand = expression static member (symbol) (operand1, operand2) = expression
COBOL
ISLISP

Indexers edit

read-write read-only write-only
ABAP Objects
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++ type& operator[](type index) { instructions } type operator[](type index) { instructions }
C# type this[type index] {
get{
instructions }
set{
instructions } }
type this[type index] { get{ instructions } } type this[type index] { set{ instructions } }
D type opIndex(type index) { instructions }
type opIndexAssign(type value, type index) { instructions }
type opIndex(type index) { instructions } type opIndexAssign(type value, type index) { instructions }
Java
Objective-C (recent Clang compiler) - (id)objectAtIndexedSubscript:(NSUInteger)index { instructions return value; } or
- (id)objectForKeyedSubscript:(id)index { instructions return value; }
- (void)setObject:(id)value atIndexedSubscript:(NSUInteger)index { instructions } or
- (void)setObject:(id)value forKeyedSubscript:(id)index { instructions }
Swift subscript (index : type) -> returntype { get { instructions } set«(newIndex)» { instructions } } subscript (index : type) -> returntype { instructions }
Eiffel[37] bracket_name alias "[]" (index: TYPE): TYPE assign set_item
do instructions end
set_item (value: TYPE; index: TYPE):
do instructions end
bracket_name alias "[]" (index: TYPE): TYPE
do instructions end
Python def __getitem__(self, index):
Tab ↹ instructions
Tab ↹ return value
def __setitem__(self, index, value):
Tab ↹ instructions
def __getitem__(self, index):
Tab ↹ instructions
Tab ↹ return value
def __setitem__(self, index, value):
Tab ↹ instructions
Visual Basic .NET Default Property Item(Index As type) As type
Get
instructions
End Get
Set(ByVal
Value As type)
instructions
End Set
End Property
Default ReadOnly Property Item(Index As type) As type
Get
instructions
End Get
End Property
Default WriteOnly Property Item(Index As type) As type
Set(ByVal
Value As type)
instructions
End Set
End Property
PHP [39]
Perl [40]
Raku «our «type »»«multi »method postcircumfix:<[ ]> is rw («$self: » type $index) { instructions ... return value; } or
«our «type »»«multi »method postcircumfix:<{ }> is rw («$self: » type $key) { instructions ... return value; }
«our «type »»«multi »method postcircumfix:<[ ]>(«$self: » type $index) { instructions ... return value; } or
«our «type »»«multi »method postcircumfix:<{ }> («$self: » type $key) { instructions ... return value; }
Ruby def [](index)
instructions
expression resulting in return value
end
def []=(index, value)
instructions
end
def [](index)
instructions
expression resulting in return value
end
def []=(index, value)
instructions
end
Windows PowerShell
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
Cobra pro[index «as type»] as type
Tab ↹ get
Tab ↹Tab ↹ instructions
Tab ↹Tab ↹ return value
Tab ↹ set
Tab ↹Tab ↹ instructions
get[index «as type»] as type
Tab ↹ instructions
Tab ↹ return value
set[index «as type»] as type
Tab ↹ instructions

Type casts edit

downcast upcast
ABAP Objects
C++ 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
Objective-C
Eiffel[37]
Python
Visual Basic .NET Shared Narrowing Operator CType(operand As type) As returntype
instructions
End Operator
Shared Widening Operator CType(operand As type) As returntype
instructions
End Operator
PHP
Perl
Raku multi method type«($self:)» is export { instructions }
Ruby
Windows PowerShell
OCaml
F#
COBOL

Member access edit

How to access members of an object x

object member class member namespace member
method field property
ABAP Objects x->methodparameters»).[41] x->field x=>field or x=>methodparameters[41]»).
C++ x.method(parameters) or
ptr->method(parameters)
x.field or
ptr->field
cls::member ns::member
Objective-C [x method«:parameter «bar:parameter ...»»] x->field x.property (2.0 only) or
[x property]
[cls method«:parameter «bar:parameter ...»»]
Smalltalk x method«:parameter «bar:parameter ...»» 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
D x.property
Python
Visual Basic .NET
Xojo
Windows PowerShell [cls]::member
F# cls.member
eC x.method«(parameters)» x.field x.property cls::member ns::member
Eiffel x.method«(parameters)» x.field {cls}.member
Ruby 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!method«(parameters)»
x.field or
x!field
cls.method«(parameters)» or
cls!method«(parameters)»
ns::member
OCaml x#method «parameters»
JavaScript x.method(parameters)
x["method"](parameters)
x.field
x["field"]
x.property
x["property"]
cls.member
cls["member"]
COBOL INVOKE x "method" «USING parameters» «RETURNING result» or
x::"method"«(«parameters»)»
property OF x INVOKE cls "method" «USING parameters» «RETURNING result» or
cls::"method"«(«parameters»)» or
property OF cls
Cobra x.method«(parameters)» x.field x.property cls.member ns.member

Member availability edit

Has member? Handler for missing member
Method Field Method Field
APL (Dyalog) 3=x.⎕NC'method' 2=x.⎕NC'method'
ABAP Objects
C++
Objective-C (Cocoa) [x respondsToSelector:@selector(method)] forwardInvocation:
Smalltalk x respondsTo: selector doesNotUnderstand:
C# (using reflection)
eC
Java
D opDispatch()
Eiffel
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) method_missing()
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
JavaScript typeof x.method === "function" field in x
COBOL

Special variables edit

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++ *this [42] NULL, nullptr
C# this base[43] null
Java super[43]
D
JavaScript super[43] (ECMAScript 6) null, undefined[44]
eC this null
Objective-C self super[43] nil
Swift self super[43] nil[45]
Python self[46] super(current_class_name, self)[7]
super() (3.x only)
None
Visual Basic .NET Me MyBase Nothing
Xojo Me / Self Parent Nil
Eiffel Current Precursor «{superclass}» «(args)»[43][47] Void
PHP $this parent[43] null
Perl $self[46] $self->SUPER[43] undef
Raku self SUPER Nil
Ruby self super«(args)»[48] nil binding
Windows PowerShell $this $NULL
OCaml self[49] super[50] [51]
F# this base[43] null
COBOL SELF SUPER NULL
Cobra this base nil

Special methods edit

String representation Object copy Value equality Object comparison Hash code Object ID
Human-readable Source-compatible
ABAP Objects
APL (Dyalog) x ⎕SRC x ⎕NS x x = y
C++ x == y[52] pointer to object can be converted into an integer ID
C# x.ToString() x.Clone() x.Equals(y) x.CompareTo(y) x.GetHashCode() System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(x)
Java x.toString() x.clone()[53] x.equals(y) x.compareTo(y)[54] x.hashCode() System.identityHashCode(x)
JavaScript x.toString()
D x.toString() or
std.conv.to!string(x)
x.stringof x == y or
x.opEquals(y)
x.opCmp(y) x.toHash()
eC x.OnGetString(tempString, null, null) or
PrintString(x)
y.OnCopy(x) x.OnCompare(y) object handle can be converted into an integer ID
Objective-C (Cocoa) x.description x.debugDescription [x copy][55] [x isEqual:y] [x compare:y][56] x.hash pointer to object can be converted into an integer ID
Swift x.description[57] x.debugDescription[58] x == y[59] x < y[60] x.hashValue[61] reflect(x).objectIdentifier!.uintValue()
Smalltalk x displayString x printString x copy x = y x hash x identityHash
Python str(x)[62] repr(x)[63] copy.copy(x)[64] x == y[65] cmp(x, y)[66] hash(x)[67] 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[68] x == y spl_object_hash(x)
Perl "$x"[69] Data::Dumper->Dump([$x],['x'])[70] Storable::dclone($x)[71] Scalar::Util::refaddr( $x )[72]
Raku ~x[69] x.perl x.clone x eqv y x cmp y x.WHICH
Ruby x.to_s x.inspect x.dup or
x.clone
x == y or
x.eql?(y)
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.hash x Oo.id x
F# string x or x.ToString() or sprintf "%O" x sprintf "%A" x x.Clone() x = y or x.Equals(y) compare x y or x.CompareTo(y) hash x or x.GetHashCode()
COBOL

Type manipulation edit

Get object type Is instance of (includes subtypes) Upcasting Downcasting
Runtime check No check
ABAP Objects [73] = ?=
C++ typeid(x) dynamic_cast<type *>(&x) != nullptr [74] dynamic_cast<type*>(ptr) (type*) ptr or
static_cast<type*>(ptr)
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][75] [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 [76]
Visual Basic .NET x.GetType() TypeOf x Is type [74] CType(x, type) or TryCast(x, type)
Xojo Introspection.GetType(x) x IsA type CType(x, type)
Eiffel x.generating_type attached {TYPE} x attached {TYPE} x as down_x
Python type(x) isinstance(x, type) [76]
PHP get_class(x) x instanceof class
Perl ref(x) x->isa("class")
Raku x.WHAT x.isa(class) [74] type(x) or
x.type
Ruby x.class x.instance_of?(type) or
x.kind_of?(type)
[76]
Smalltalk x class x isKindOf: class
Windows PowerShell x.GetType() x -is [type] [74] [type]x or x -as [type]
OCaml [77] (x :> type)
F# x.GetType() x :? type (x :?> type)
COBOL x AS type[74]

Namespace management edit

Import namespace Import item
qualified unqualified
ABAP Objects
C++ 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

Contracts edit

Precondition Postcondition Check Invariant Loop
ABAP Objects
C++
C# Spec#:
type foo( «parameters» )
    requires expression
{
    body
}
Spec#:
type foo( «parameters» )
    ensures expression
{
    body
}
Java
Objective-C
Visual Basic .NET
D f
in { asserts }
body{
instructions }
f
out (result) { asserts }
body{
instructions }
assert(expression) invariant() { expression }
Eiffel f
require tag: expression
do end
f
do
ensure
tag: expression
end
f
do
check tag: expression end
end
class X
invariant tag: expression
end
from instructions
invariant
tag: expression
until
expr
loop
instructions
variant
tag: expression
end
Python
PHP
Perl
Raku PRE { condition } POST { condition }
Ruby
Windows PowerShell
OCaml
F#
COBOL

See also edit

References and notes edit

  1. ^ parameter = argument may be repeated if the constructor has several parameters
  2. ^ SAP reserved to himself the use of destruction
  3. ^ a b c d e f g h i j k l This language uses garbage collection to release unused memory.
  4. ^ This syntax creates an object value with automatic storage duration
  5. ^ This syntax creates an object with dynamic storage duration and returns a pointer to it
  6. ^ OCaml objects can be created directly without going through a class.
  7. ^ a b c d e f g This language supports multiple inheritance. A class can have more than one parent class
  8. ^ Not providing a parent class makes the class a root class. In practice, this is almost never done. One should generally use the conventional base class of the framework one is using, which is NSObject for Cocoa and GNUstep, or Object otherwise.
  9. ^ Usually the @interface portion is placed into a header file, and the @interface portion is placed into a separate source code file.
  10. ^ Prefixes to class and protocol names conventionally used as a kind of namespace
  11. ^ In Python interfaces are classes which methods have pass as their bodies
  12. ^ The class is an Object.
    Just send a message to the superclass (st-80) or the destination namespace (Visualworks).
  13. ^ The namespace is an Object.
    Just send a message to the parent namespace.
  14. ^ A finalizer is called by the garbage collector when an object is about to be garbage-collected. There is no guarantee on when it will be called or if it will be called at all.
  15. ^ In ABAP, the constructor is to be defined like a method (see comments about method) with the following restrictions: the method name must be "constructor", and only "importing" parameters can be defined
  16. ^ An optional comma-separated list of initializers for member objects and parent classes goes here. The syntax for initializing member objects is
    "member_name(parameters)"
    This works even for primitive members, in which case one parameter is specified and that value is copied into the member. The syntax for initializing parent classes is
    "class_name(parameters)".
    If an initializer is not specified for a member or parent class, then the default constructor is used.
  17. ^ Any Eiffel procedure can be used as a creation procedure, aka constructors. See Eiffel paragraph at Constructor (computer science).
  18. ^ Implementing {DISPOSABLE}.dispose ensures that dispose will be called when object is garbage collected.
  19. ^ This "initializer" construct is rarely used. Fields in OCaml are usually initialized directly in their declaration. Only when additional imperative operations are needed is "initializer" used. The "parameters to the constructor" in other languages are instead specified as the parameters to the class in OCaml. See the class declaration syntax for more details.
  20. ^ This syntax is usually used to overload constructors
  21. ^ In JavaScript, constructor is an object.
  22. ^ Constructors can be emulated with a factory method returning a class instance.
  23. ^ a b c Scope identifier must appear once in the file declaration, all variable declarations after this scope identifier have his scope, until another scope identifier or the end of class declaration is reached
  24. ^ In ABAP, specific fields or methods are not declared as accessible by outside things. Rather, outside classes are declared as friends to have access to the class's fields or methods.
  25. ^ In C++, specific fields are not declared as accessible by outside things. Rather, outside functions and classes are declared as friends to have access to the class's fields. See friend function and friend class for more details.
  26. ^ Just send a message to the class
    class addInstVarName: field. class removeInstVarName: field. 
  27. ^ a b c d Just assign a value to it in a method
  28. ^ Python doesn't have private fields - all fields are publicly accessible at all times. A community convention exists to prefix implementation details with one underscore, but this is unenforced by the language.
  29. ^ All class data is 'private' because the COBOL standard does not specify any way to access it.
  30. ^ The declaration and implementation of methods in ABAP are separate. methods statement is to be used inside the class definition. method (without "s") is to be used inside the class implementation. parameter = argument can be repeated if there are several parameters.
  31. ^ In ABAP, the return parameter name is explicitly defined in the method signature within the class definition
  32. ^ In C++, declaring and implementing methods is usually separate. Methods are declared in the class definition (which is usually included in a header file) using the syntax
  33. ^ Although the body of a method can be included with the declaration inside the class definition, as shown in the table here, this is generally bad practice. Because the class definition must be included with every source file which uses the fields or methods of the class, having code in the class definition causes the method code to be compiled with every source file, increasing the size of the code. Yet, in some circumstances, it is useful to include the body of a method with the declaration. One reason is that the compiler will try to inline methods that are included in the class declaration; so if a very short one-line method occurs, it may make it faster to allow a compiler to inline it, by including the body along with the declaration. Also, if a template class or method occurs, then all the code must be included with the declaration, because only with the code can the template be instantiated.
  34. ^ a b Just assign a function to it in a method
  35. ^ Alternative implementation:
    def bar(): doc = "The bar property." def fget(self): return self._bar def fset(self, value): self._bar = value return locals() bar = property(**bar()) 
  36. ^ these examples need the Class::Accessor module installed
  37. ^ a b c Although Eiffel does not support overloading of operators, it can define operators
  38. ^ PHP does not support operator overloading natively, but support can be added using the "operator" PECL package.
  39. ^ The class must implement the ArrayAccess interface.
  40. ^ The class must overload '@{}' (array dereference) or subclass one of Tie::Array or Tie::StdArray to hook array operations
  41. ^ a b In ABAP, arguments must be passed using this syntax:
    x->method(«exporting parameter = argument» «importing parameter = argument» «changing parameter = argument» «returning value(parameter)»
    parameter = argument can be repeated if there are several parameters
  42. ^ C++ doesn't have a "super" keyword, because multiple inheritance is possible, and so it may be ambiguous which base class is referenced. Instead, the BaseClassName::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]
  43. ^ a b c d e f g h i The keyword here is not a value, and it can only be used to access a method of the superclass.
  44. ^ But be afraid, they have not the same value.
  45. ^ only for Optional types
  46. ^ a b In this language, instance methods are passed the current object as the first parameter, which is conventionally named "self", but this is not required to be the case.
  47. ^ "Precursor" in Eiffel is actually a call to the method of the same name in the superclass. So Precursor(args) is equivalent to "super.currentMethodName(args)" in Java. There is no way of calling a method of different name in the superclass.
  48. ^ "super" in Ruby, unlike in other languages, is actually a call to the method of the same name in the superclass. So super(args) in Ruby is equivalent to "super.currentMethodName(args)" in Java. There is no way of calling a method of different name in the superclass.
  49. ^ In OCaml, an object declaration can optionally start with a parameter which will be associated with the current object. This parameter is conventionally named "self", but this is not required to be the case. It is good practice to put a parameter there so that one can call one's own methods.
  50. ^ In OCaml, an inheritance declaration ("inherit") can optionally be associated with a value, with the syntax "inherit parent_class «parameters» as super". Here "super" is the name given to the variable associated with this parent object. It can be named differently.
  51. ^ However, if the ability to have an "optional" value in OCaml is needed, then wrap the value inside an 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.
  52. ^ assuming that "x" and "y" are the objects (and not pointers). Can be customized by overloading the object's == operator
  53. ^ Only accessible from within the class, since the 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.
  54. ^ The class should implement the interface Comparable for this method to be standardized.
  55. ^ Implemented by the object's copyWithZone: method
  56. ^ compare: is the conventional name for the comparison method in Foundation classes. However, no formal protocol exists
  57. ^ Only if object conforms to the Printable protocol
  58. ^ Only if object conforms to the DebugPrintable protocol
  59. ^ Only if object conforms to the Equatable protocol
  60. ^ Only if object conforms to the Comparable protocol
  61. ^ Only if object conforms to the hashValue protocol
  62. ^ Can be customized by the object's __str__() method
  63. ^ Can be customized by the object's __repr__() method
  64. ^ Can be customized by the object's __copy__() method
  65. ^ Can be customized by the object's __eq__() method
  66. ^ Only in Python 2.x and before (removed in Python 3.0). Can be customized by the object's __cmp__() method
  67. ^ Can be customized by the object's __hash__() method. Not all types are hashable (mutable types are usually not hashable)
  68. ^ Can be customized by the object's __clone() method
  69. ^ a b Can be customized by overloading the object's string conversion operator
  70. ^ This example requires useing Data::Dumper
  71. ^ This example requires useing Storable
  72. ^ This example requires useing Scalar::Util
  73. ^ Run-time type information in ABAP can be gathered by using different description Classes like CL_ABAP_CLASSDESCR.
  74. ^ a b c d e Upcasting is implicit in this language. A subtype instance can be used where a supertype is needed.
  75. ^ Only for non-class objects. If 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.
  76. ^ a b c This language is dynamically typed. Casting between types is unneeded.
  77. ^ This language doesn't give run-time type information. It is unneeded because it is statically typed and downcasting is impossible.

comparison, programming, languages, object, oriented, programming, this, article, require, cleanup, meet, wikipedia, quality, standards, specific, problem, this, article, reference, section, contains, many, footnotes, lists, external, references, sources, plea. 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 Please help improve this article if you can June 2013 Learn how and when to remove this template message 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 Contents 1 Object construction and destruction 2 Class declaration 3 Class members 3 1 Constructors and destructors 3 2 Fields 3 3 Methods 3 4 Properties 3 4 1 Manually implemented 3 4 2 Automatically implemented 3 5 Overloaded operators 3 5 1 Standard operators 3 5 2 Indexers 3 5 3 Type casts 4 Member access 5 Member availability 6 Special variables 7 Special methods 8 Type manipulation 9 Namespace management 10 Contracts 11 See also 12 References and notesObject construction and destruction editconstruction destructionABAP Objects b data b variable b type ref to b class b b br b create object b variable b exporting b parameter argument 1 2 3 APL Dyalog variable b NEW b class parameters b EX b variable b b C class variable b b parameters b b b b 4 orclass b a href Pointer computer programming html title Pointer computer programming a b variable b a href New C 2B 2B html class mw redirect title New C new a b class b b parameters b b b b 5 b a href Delete C 2B 2B html class mw redirect title Delete C delete a b pointer b b C class variable b new b class b b parameters b b variable b Dispose b 3 Java 3 D b destroy b variable b b eC class instance handle b b properties data members assignments instance method overrides b b b delete b instance handle b b Objective C Cocoa class b a href Pointer computer programming html title Pointer computer programming a b variable b b class b alloc init b or class b a href Pointer computer programming html title Pointer computer programming a b variable b b class b alloc b initWithFoo b b parameter bar b b parameter b b b b variable b release b Swift b let b variable b b class b b parameters b b Python variable b b class b b parameters b b b del b variable 3 Normally not needed Visual Basic NET b Dim b variable b As New b class b b parameters b b variable b Dispose b 3 Xojo b Dim b variable b As New b class b b parameters b b variable b Nil b Eiffel b create b variable or b create b b b TYPE b b variable b b make foo b b parameters b b orvariable b create b b b TYPE b b orvariable b create b TYPE b b make foo b b parameters b b 3 PHP b a href Sigil computer programming html title Sigil computer programming a b variable b new b class b b parameters b b b unset b variable b b 3 Perl 5 b my b b b variable b b class b gt new b b b parameters b b b b b undef b variable b b Raku b my b variable b b class b new b b b parameters b b b b variable b undefine b Ruby variable b b class b new b b b parameters b b 3 Windows PowerShell b b variable b New Object b b TypeName b class b ArgumentList b parameters b Remove Variable b b Name b variableOCaml b let b variable b new b class parameters or b let b variable b object b members b end b 6 3 F b let b variable b b b new b class b b parameters b b 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 b var b variable b new b class parameters or b var b variable b b key1 b b value1 b b key2 b b value2 b b 3 Object Pascal Delphi ClassVar b b ClassType ConstructorName b b parameters b b ClassVar b Free b 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 b INVOKE b class b NEW b b RETURNING b variable or b MOVE b class b NEW b b TO b variableCobra variable b as b class b b class b b parameters b b variable b dispose b ISLISP b setq b variable b create b b class b lt some class gt field 1 value 1 field 2 value 2 3 Class declaration editclass protocol namespaceABAP Objects b class b name b definition b b inheriting from b parentclass b b b interfaces b interfaces b b method and field declarations b endclass b br b class b name b implementation b method implementations b endclass b b interface b name b b members b endinterface b APL Dyalog b Class b name b b parentclass b b interfaces members b EndClass b b Interface b namemembers b EndInterface b b Namespace b namemembers b EndNamespace b C b class b name b public b parentclasses 7 b b members b b b namespace b name b b members b b C b class b name b b parentclass b b interfaces b b members b b b interface b name b b parentinterfaces b b members b b D b module b name b b br memberseC b class b name b b base class b b default member values assignments members b b b namespace b name Java b class b name b extends b parentclass b implements b interfaces b b members b b b interface b name b extends b parentinterfaces b b members b b b package b name b b membersPHP b namespace b name b b membersObjective C b interface b name b b parentclass 8 b lt b protocols b gt b b b instance fields b b method and property declarations b end br implementation b name method implementations b end b 9 b protocol b name b lt b parentprotocols b gt b members b end b 10 Swift b class b name b b parentclass b b protocols b b members b b b protocol b name b b parentprotocols b b members b b Python b class b name b b parentclasses sup id cite ref multi 7 1 class reference a href cite note multi 7 7 a sup b b b br style mw parser output keyboard key border 1px solid aaa border radius 0 2em box shadow 0 1em 0 1em 0 2em rgba 0 0 0 0 1 background color f9f9f9 background image linear gradient to bottom eee f9f9f9 eee color 000 padding 0 1em 0 3em font family inherit font size 0 85em style kbd class keyboard key nowrap Tab kbd b members 11 b all b member1 b b member2 b b Visual Basic NET b Class b name b Inherits b parentclass b Implements b interfaces br members br b End Class b b Interface b name b Inherits b parentinterfaces br members br b End Interface b b Namespace b name br members br b End Namespace b Xojo b Class b name b Inherits b parentclass b Implements b interfaces br members br b End Class b b Interface b name b Inherits b parentinterfaces br members br b End Interface b b Module b name br members br b End Module b Eiffel b class b name b inherit b parentclasses sup id cite ref multi 7 2 class reference a href cite note multi 7 7 a sup br members br b end b Perl b package b name b b b ISA qw b parentclasses sup id cite ref multi 7 3 class reference a href cite note multi 7 7 a sup b b members b 1 b b package b name b b membersRaku b class b name b is b parentclass b is b parentclass sup id cite ref multi 7 4 class reference a href cite note multi 7 7 a sup b does b role b does b role b b members b b b role b name b does b role b does b role b b members b b b module b name b b members b b Ruby b class b name b lt b parentclass br members br b end b b module b name br members br b end b Windows PowerShell OCaml b class b name parameters b object b b self b b inherit b parentclass parameters b inherit b parentclass parameters sup id cite ref multi 7 5 class reference a href cite note multi 7 7 a sup members b end b b module b name br membersF b type b name b b parameters b b b b b as this b b class b b inherit b parentclass b b parameters b b b as base b members b interface b interface b with b implementation b interface b interface b with b implementation b end b b type b name b interface b members b end b b namespace b name br membersSmalltalk 12 13 JavaScript ES6 classname b extends b parentclass b b members b b Object Pascal Delphi b ClassName Class b b ClassParent Interfaces b br private br Private members include Methods and Fields br public br Public members br protected br Protected members br published br Published members br end b package b name b b membersScala class ConcreteClass constructor params extends ParentClass with Trait1 with Trait2 with Trait2 members trait TraitName extends OtherTrait1 with OtherTrait2 with OtherTrait3 members package nameCOBOL b CLASS ID b name b INHERITS b b FROM b parentclasses b b b FACTORY b b IMPLEMENTS b interfaces b b class members b END FACTORY b b OBJECT b b IMPLEMENTS b interfaces b b instance members b END OBJECT b b END CLASS b name b b b INTERFACE ID b name b INHERITS b b FROM b interfaces b b members b END INTERFACE b name b b Cobra b class b name b inherits b parentclass b implements b interfaces br kbd class keyboard key nowrap Tab kbd members b interface b name b inherits b parentinterfaces br kbd class keyboard key nowrap Tab kbd members b namespace b name br kbd class keyboard key nowrap Tab kbd membersISLISP b defclass b name base class x b initform b 0 b accessor b get x b initarg b x b abstractp b nil Class members editConstructors and destructors edit constructor destructor finalizer 14 ABAP Objects b methods constructor b b importing b parameter argument br b method constructor b instructions b endmethod b 15 APL Dyalog b b name b Implements Constructor b b Base b expr instructions b b b b name b Implements Destructor b instructions b b C class b b parameters b b b b initializers 16 b b instructions b b b b class b b instructions b b C class b b parameters b b instructions b b b void Dispose b instructions b b b b class b b instructions b b D b this b parameters b b instructions b b b this b instructions b b eC class b b instructions b b class b b instructions b b Java class b b parameters b b instructions b b b void finalize b instructions b b Eiffel 17 18 Objective C Cocoa b id init b instructions b return self b or br b id b initWithFoo b b parameter bar b b parameter b b instructions b return self b b void dealloc b instructions b b b void finalize b instructions b b Swift b init b parameters b b instructions b b b deinit b instructions b b Python b def init self b b b parameters b b br kbd class keyboard key nowrap Tab kbd instructions b def del self b br kbd class keyboard key nowrap Tab kbd instructionsVisual Basic NET b Sub New b parameters b b br instructions br b End Sub b b Sub Dispose b br instructions br b End Sub b b Overrides Sub Finalize b br instructions br b End Sub b Xojo b Sub Constructor b parameters b b br instructions br b End Sub b b Sub Destructor b br instructions br b End Sub b PHP b function construct b parameters b b instructions b b b function destruct b instructions b b Perl b sub new my class b b b parameters b my self b instructions b bless self class return self b b sub DESTROY my self b instructions b b Raku b submethod BUILD b instructions b b or br b multi b b method new b self b b parameters b self bless b field1 b gt b value1 b b instructions b b b submethod DESTROY b instructions b b Ruby b def initialize b b b parameters b b br instructions br b end b Windows PowerShell OCaml b initializer b instructions 19 F b do b instructions or br b new b parameters b b expression 20 b member this Dispose b instructions b override this Finalize b instructionsJavaScript b function b name b b parameters b b b b instructions b b 21 JavaScript ES6 constructor parameters b b instructions b b COBOL 22 Cobra b cue init b parameters b b br kbd class keyboard key nowrap Tab kbd b base init b br kbd class keyboard key nowrap Tab kbd instructions b def b dispose br kbd class keyboard key nowrap Tab kbd instructionsISLISP b defmethod b initialize object instance lt class name gt initvalues Fields edit public private protected friendABAP Objects b public section sup id cite ref abapsection 23 0 class reference a href cite note abapsection 23 23 a sup data b field b type b type b b b private section sup id cite ref abapsection 23 1 class reference a href cite note abapsection 23 23 a sup data b field b type b type b b b protected section sup id cite ref abapsection 23 2 class reference a href cite note abapsection 23 23 a sup data b field b type b type b b 24 APL Dyalog b Field Public b field b b value b Field b b Private b field b b value C b public b type field b b b private b type field b b b protected b type field b b 25 C b public b type field b b value b b b private b type field b b value b b b protected b type field b b value b b b internal b type field b b value b b D b package b type field b b value b b Java b protected b type field b b value b b type field b b value b b eC b public b type field b b b private b type field b b Eiffel b feature b br field TYPE b feature NONE b br field TYPE b feature b current class b b br field TYPE b feature FRIEND b br field TYPEObjective C b public b type field b b b private b type field b b b protected b type field b b b package b type field b b Swift Smalltalk 26 Python b self b field b b value 27 28 Visual Basic NET b Public b field b As b type b b value b Private b field b As b type b b value b Protected b field b As b type b b value b Friend b field b As b type b b value Xojo b Public b field b As b type b b value b Private b field b As b type b b value b Protected b field b As b type b b value PHP b public b field b b value b b b private b field b b value b b b protected b field b b value b b Perl b self gt b field b b value b b 27 Raku b has b type b b field b is rw b b has b type b b field Ruby b a href Sigil computer programming html title Sigil computer programming a b field b b value 27 Windows PowerShell b Add Member b br b MemberType b b NoteProperty b br b Name b Bar b Value b value br b InputObject b variable OCaml b val b b mutable b field b b value F b let b b mutable b field b b value JavaScript b this b field b b value br b this b field value 27 COBOL level number field clauses 29 Cobra b var b field b as b type b b value b var b b b field b as b type b b value b var b b b field b as b type b b value ISLISP field b initform b value b accessor b accessor name b initarg b keyword Methods edit basic void method value returning methodABAP Objects b methods b name b importing b parameter argument b exporting b parameter argument b changing b parameter argument b returning value b parameter b b br b method b name b b instructions b endmethod b 30 31 APL Dyalog b b left argument name right arguments instructions b b b b result b b left argument name right arguments instructions b b C 32 type foo b b parameters b b The implementation of methods is usually provided in a separate source file with the following syntax type class b b foo b b parameters b b instructions b b 33 b void b foo b b parameters b b instructions b b type foo b b parameters b b instructions b return b value b b C DJavaeC b void b type of this b b foo b b parameters b b instructions b b type type of this b b foo b b parameters b b instructions b return b value b b Eiffel foo b b parameters b b br b do b br instructions br b end b foo b b parameters b b TYPE br b do b br instructions br b Result b value br b end b Objective C b void b foo b b parameter bar b b parameter b b instructions b b b b type b b foo b b parameter bar b b parameter b b instructions b return b value b b Swift b func b foo b b parameters b b instructions b b b func b foo b b parameters b gt b type b b instructions b return b value b b Python b def b foo b self b b b parameters b br kbd class keyboard key nowrap Tab kbd b instructions b def b foo b self b b b parameters b br kbd class keyboard key nowrap Tab kbd b instructions b br kbd class keyboard key nowrap Tab kbd return b valueVisual Basic NET b Sub b Foo b b parameters b br b instructions b br End Sub b b Function b Foo b b parameters b As b type b br b instructions br br b Return b value br b End Function b Xojo b Sub b Foo b b parameters b br b instructions b br End Sub b b Function b Foo b b parameters b As b type b br b instructions br br b Return b value br b End Function b PHP b function b foo b b parameters b void b instructions b b b function b foo b b parameters b b type b b instructions b return b value b b Perl b sub b foo b my self b b b parameters b b instructions b b b sub b foo b my self b b b parameters b b instructions b return b value b b Raku b has b b multi b b method b foo b b self b b parameters b b instructions b b b has b type b multi b b method b foo b b self b b parameters b b instructions b return b value b b Ruby b def b foo b b parameters b b br instructions br b end b b def b foo b b parameters b b br instructions br expression resulting in return value br b end b br or br b def b foo b b parameters b b br instructions br b return b value br b end b Windows PowerShell b Add Member b b MemberType b b ScriptMethod b b Name b foo b Value b b b b param b parameters b b b b instructions b InputObject b variable b Add Member b b MemberType b b ScriptMethod b b Name b foo b Value b b b b param b parameters b b b b instructions b return b value b InputObject b variableOCaml b method b foo parameters b b expressionF b member this b foo b b parameters b b expressionJavaScript b this b method b function b parameters b b instructions b b br name b prototype b method b function b parameters b b instructions b b 34 b this b method b function b parameters b b instructions b return b value b b br name b prototype b method b function b parameters b b instructions b return b value b b 34 Javascript ES6 foo b b parameters b b instructions b b foo b b parameters b b instructions b return b value b b COBOL b METHOD ID b foo b b br b DATA DIVISION b br b LINKAGE SECTION b br parameter declarations br b PROCEDURE DIVISION b b USING b parameters b b instructions b END METHOD b foo b b b METHOD ID b foo b b br b DATA DIVISION b br b LINKAGE SECTION b br parameter declarations br result var declaration br b PROCEDURE DIVISION b b USING b parameters b RETURNING b result var b b instructions b END METHOD b foo b b Cobra b def b foo b b parameters b b br kbd class keyboard key nowrap Tab kbd instructions b def b foo b b parameters b as b type br kbd class keyboard key nowrap Tab kbd instructions br kbd class keyboard key nowrap Tab kbd b return b valueISLISP b defgeneric b method arg1 arg2 br b defmethod b method arg1 lt class1 gt arg2 lt class2 gt Properties edit How to declare a property named Bar Manually implemented edit read write read only write onlyABAP Objects APL Dyalog b Property b Bar b b result b Get b instructions b b b Set b argumentsinstructions b b b EndProperty b Bar b Property b Bar b b result b Get b instructions b b b EndProperty b Bar b Property b Bar b Set b argumentsinstructions b b b EndProperty b BarC C type Bar b br get b instructions b return b value b b b br set b instructions b b type Bar b get b instructions b return b value b b b b type Bar b set b instructions b b D b property b type bar b b instructions b return b value b b b br property b type bar b b type value b b instructions b return b value b b b b b property b type bar b b instructions b return b value b b b b b property b type bar b b type value b b instructions b return b value b b b b eC b property b type Bar b br get b instructions b return b value b b b br set b instructions b b b property b type Bar b get b instructions b return b value b b b b b property b type Bar b set b instructions b b Java Objective C 2 0 Cocoa b property readwrite b type bar b b br and then inside implementation br b b type b b bar b b instructions b b br b void b setBar b b type b b value b b instructions b b b property readonly b type bar b b br and then inside implementation br b b type b b bar b b instructions b b Swift b var b bar b b type b get b instructions b set b b b newBar b b b b instructions b b b var b bar b b type b b instructions b b Eiffel b feature b Access br x TYPE b assign b set x br b feature b Settings br set x a x b like b x b do b instructions b ensure b x set verification b end b Python b def b setBar b self b value b b br kbd class keyboard key nowrap Tab kbd instructions b br def b getBar b self br kbd class keyboard key nowrap Tab kbd b instructions br kbd class keyboard key nowrap Tab kbd b return b value br bar b property b getBar b b setBar b b 35 b def b getBar b self b br kbd class keyboard key nowrap Tab kbd instructions br kbd class keyboard key nowrap Tab kbd b return b value br bar b property b getBar b b b def b setBar b self b value b b br kbd class keyboard key nowrap Tab kbd instructions br bar b property fset b setBar b b Visual Basic NET b Property b Bar b As b type br b Get br b instructions br b Return b value br b End Get br Set ByVal b Value b As b type b b br instructions b br End Set br End Property b b ReadOnly Property b Bar b As b type br b Get br b instructions br b Return b value br b End Get br End Property b b WriteOnly Property b Bar b As b type br b Set ByVal b Value b As b type b b br instructions br b End Set br End Property b Xojo b ComputedProperty b Bar b As b type br b Get br b instructions br b Return b value br b End Get br Set ByVal b Value b As b type b b br instructions b br End Set br End ComputedProperty b b ComputedProperty b Bar b As b type br b Get br b instructions br b Return b value br b End Get br End ComputedProperty b b ComputedProperty b Bar b As b type br b Set b value b As b type b b br instructions br b End Set br End ComputedProperty b PHP b function get b property b br switch b property b br case b span class nowrap style padding left 0 1em span Bar span class nowrap style padding left 0 1em span b b instructions b return b value b br br function set b property b b value b br switch b property b br case b span class nowrap style padding left 0 1em span Bar span class nowrap style padding left 0 1em span b b instructions b br b b function get b property b br switch b property b br case b span class nowrap style padding left 0 1em span Bar span class nowrap style padding left 0 1em span b b instructions b return b value b br b b function set b property b b value b br switch b property b br case b span class nowrap style padding left 0 1em span Bar span class nowrap style padding left 0 1em span b b instructions b br b Perl b sub b Bar br b my b self b shift b br b if b b my b Bar b shift b br setter br self gt Bar Bar br return self br b else b br getter br b return b self gt Bar br br b sub b Bar br b my b self b shift b br b if b b my b Bar b shift b br read only br b die b Bar is read only n br b else b br getter br b return b self gt Bar br br b sub b Bar br b my b self b shift b br b if b b my b Bar b shift b br setter br self gt Bar Bar br return self br b else b br write only br b die b Bar is write only n br br Raku Ruby b def b bar br instructions br expression resulting in return value br b end b br b def b bar b b value b b br instructions br b end b b def b bar br instructions br expression resulting in return value br b end b b def b bar b b value b b br instructions br b end b Windows PowerShell b Add Member b br b MemberType b b ScriptProperty b br b Name b Bar b Value b b b instructions b return b value b b br b SecondValue b b b instructions b b br b InputObject b variable b Add Member b br b MemberType b b ScriptProperty b br b Name b Bar b Value b b b instructions b return b value b b br b InputObject b variable b Add Member b br b MemberType b b ScriptProperty b br b Name b Bar b SecondValue b instructions b b br b InputObject b variableOCaml F b member this b Bar b with get b expression b and set b value b b expression b member this b Bar b b expression b member this b Bar b with set b value b b expressionJavaScript ES6 b get b bar b b parameters b b b b instructions b return b value b b s b et b bar b b parameters b b instructions b b getbar b b parameters b b b b instructions b return b value b b b set b bar b b parameters b b instructions b b COBOL b METHOD ID GET PROPERTY b bar b b br b DATA DIVISION b br b LINKAGE SECTION b br return var declaration br b PROCEDURE DIVISION RETURNING b return var b b instructions b END METHOD b br b METHOD ID SET PROPERTY b bar b b br b DATA DIVISION b br b LINKAGE SECTION b br value var declaration br b PROCEDURE DIVISION USING b value var b b instructions b END METHOD b b METHOD ID GET PROPERTY b bar b b br b DATA DIVISION b br b LINKAGE SECTION b br return var declaration br b PROCEDURE DIVISION RETURNING b return var b b instructions b END METHOD b b METHOD ID SET PROPERTY b bar b b br b DATA DIVISION b br b LINKAGE SECTION b br value var declaration br b PROCEDURE DIVISION USING b value var b b instructions b END METHOD b Cobra b pro b bar b as b type br kbd class keyboard key nowrap Tab kbd b get b br kbd class keyboard key nowrap Tab kbd kbd class keyboard key nowrap Tab kbd instructions br kbd class keyboard key nowrap Tab kbd kbd class keyboard key nowrap Tab kbd b return b value br kbd class keyboard key nowrap Tab kbd b set b br kbd class keyboard key nowrap Tab kbd kbd class keyboard key nowrap Tab kbd instructions b get b bar b as b type br kbd class keyboard key nowrap Tab kbd instructions br kbd class keyboard key nowrap Tab kbd b return b value b set b bar b as b type br kbd class keyboard key nowrap Tab kbd instructionsISLISP Automatically implemented edit read write read only write onlyABAP Objects C C type Bar b get set b type Bar b get private set b type Bar b private get set b D Java Objective C 2 0 Cocoa b property readwrite b type bar b b br and then inside implementation br b synthesize b bar b b b property readonly b type bar b b br and then inside implementation br b synthesize b bar b b Swift b var b bar b b type b let b bar b b type EiffelPython b property b br b def b bar b self b br kbd class keyboard key nowrap Tab kbd instructions br b b bar b setter b br b def b bar b self b value br kbd class keyboard key nowrap Tab kbd instructions b property b br b def b bar b self b br kbd class keyboard key nowrap Tab kbd instructions bar b property b br b b bar b setter b br b def b bar b self b value br kbd class keyboard key nowrap Tab kbd instructionsVisual Basic NET b Property b Bar b As b type b b initial value VB 10 PHPPerl 36 b use b b base b b qw b Class Accessor br b PACKAGE b gt b mk accessors b Bar b use b b base b b qw b Class Accessor br b PACKAGE b gt b mk ro accessors b Bar b use b b base b b qw b Class Accessor br b PACKAGE b gt b mk wo accessors b Bar Raku Ruby b attr accessor b bar b attr reader b bar b attr writer b barWindows PowerShellOCaml F b member val b Bar b b value b with get set b COBOL level number bar clauses b PROPERTY b level number bar clauses b PROPERTY WITH NO SET b level number bar clauses b PROPERTY WITH NO GET b Cobra b pro b bar b from var b b as b type b get b bar b from var b b as b type b set b bar b from var b b as b type Overloaded operators edit Standard operators edit unary binary function callABAP Objects C type b operator b symbol b b instructions b b type b operator b symbol b b type operand2 b b instructions b b type b operator b parameters b b instructions b b C b static b type b operator b symbol b b type operand b b instructions b b b static b type b operator b symbol b b type operand1 b b type operand2 b b instructions b b D type b opUnary string b s b if b s b b symbol b b instructions b b type b opBinary string b s b b type operand2 b if b s b b symbol b b instructions b b br type b opBinaryRight string b s b b type operand1 b if b s b b symbol b switch b s b b instructions b b type b opCall b parameters b b instructions b b Java Objective CSwift b func b symbol b b operand1 b b type b gt b returntype b b instructions b b outside class b func b symbol b b operand1 b b type1 b b operand2 b b type2 b gt b returntype b b instructions b b outside class Eiffel 37 op name b alias b symbol b b TYPE br b do b instructions b end b op name b alias b symbol b b operand TYPE1 b b TYPE2 br b do b instructions b end b Python b def b opname b self br kbd class keyboard key nowrap Tab kbd b instructions b br kbd class keyboard key nowrap Tab kbd return b value b def b opname b self b operand2 b br kbd class keyboard key nowrap Tab kbd b instructions b br kbd class keyboard key nowrap Tab kbd return b value b def call self b b b parameters b br kbd class keyboard key nowrap Tab kbd b instructions b br kbd class keyboard key nowrap Tab kbd return b valueVisual Basic NET b Shared Operator b symbol b b operand b As b type b As b type b br b instructions b br End Operator b b Shared Operator b symbol b b operand1 b As b type b b operand2 b As b type b As b type b br b instructions b br End Operator b Xojo b Function Operator b name b b operand b As b type b As b type b br b instructions b br End Function b PHP 38 b function invoke b parameters b b instructions b b PHP 5 3 Perl b use overload b symbol b gt sub my self b instructions b b b use overload b symbol b gt sub my self b operand2 b b operands reversed b b instructions b b Raku b our b type b multi b b method prefix lt b symbol b gt b operand b b b b instructions b return b value b b b b or br b our b type b multi b b method postfix lt b symbol b gt b operand b b b b instructions b return b value b b b b or br b our b type b multi b b method circumfix lt b symbol1 symbol2 b gt b operand b b b b instructions b return b value b b b b b our b type b multi b b method infix lt b symbol b gt b operand1 b b type operand2 b b instructions b return b value b b b b b our b type b multi b b method postcircumfix lt gt b self b b parameters b b instructions b b Ruby b def b symbol br instructions br expression resulting in return value br b end b b def b symbol b b operand2 b b br instructions br expression resulting in return value br b end b Windows PowerShell OCamlF b static member b symbol b b operand b b expression b static member b symbol b b b b operand1 b b operand2 b b expression COBOL ISLISP Indexers edit read write read only write onlyABAP Objects APL Dyalog b Property Numbered Default b name b b result b Get b instructions b b b Set b argumentsinstructions b b b EndProperty b Bar b Property Numbered Default b Bar b b result b Get b instructions b b b EndProperty b Bar b Property Numbered Default b Bar b Set b argumentsinstructions b b b EndProperty b BarC type b amp operator b type index b b instructions b b type b operator b type index b b instructions b b C type b this b type index b br get b instructions b br set b instructions b b type b this b type index b get b instructions b b type b this b type index b set b instructions b b D type b opIndex b type index b b instructions b b br type b opIndexAssign b type value b b type index b b instructions b b type b opIndex b type index b b instructions b b type b opIndexAssign b type value b b type index b b instructions b b Java Objective C recent Clang compiler b id objectAtIndexedSubscript NSUInteger b index b b instructions b return b value b b or br b id objectForKeyedSubscript id b index b b instructions b return b value b b b void setObject id b value b atIndexedSubscript NSUInteger b index b b instructions b b or br b void setObject id b value b forKeyedSubscript id b index b b instructions b b Swift b subscript b index b b type b gt b returntype b get b instructions b set b b b newIndex b b b b instructions b b b subscript b index b b type b gt b returntype b b instructions b b Eiffel 37 bracket name b alias b index TYPE b b TYPE b assign b set item br b do b instructions b end b br set item b b value TYPE index TYPE b b br b do b instructions b end b bracket name b alias b index TYPE b b TYPE br b do b instructions b end b Python b def getitem self b index b br b kbd class keyboard key nowrap Tab kbd instructions br kbd class keyboard key nowrap Tab kbd b return b value br b def setitem self b index b b value b b br kbd class keyboard key nowrap Tab kbd instructions b def getitem self b index b br b kbd class keyboard key nowrap Tab kbd instructions br kbd class keyboard key nowrap Tab kbd b return b value b def setitem self b index b b value b b br kbd class keyboard key nowrap Tab kbd instructionsVisual Basic NET b Default Property Item b Index b As b type b As b type b br Get br b instructions b br End Get br Set ByVal b Value b As b type b br b instructions b br End Set br End Property b b Default ReadOnly Property Item b Index b As b type b As b type b br Get br b instructions b br End Get br End Property b b Default WriteOnly Property Item b Index b As b type b As b type b br Set ByVal b Value b As b type b br b instructions b br End Set br End Property b PHP 39 Perl 40 Raku b our b type b multi b b method postcircumfix lt gt is rw b self b b type index b b instructions b return b value b b b b or br b our b type b multi b b method postcircumfix lt gt is rw b self b b type key b b instructions b return b value b b b b b our b type b multi b b method postcircumfix lt gt b self b b type index b b instructions b return b value b b b b or br b our b type b multi b b method postcircumfix lt gt b self b b type key b b instructions b return b value b b b b Ruby b def b index b b br instructions br expression resulting in return value br b end b br b def b index value b b br instructions br b end b b def b index b b br instructions br expression resulting in return value br b end b b def b index value b b br instructions br b end b Windows PowerShell OCamlF b member this Item with get b index b b expression b and set b index value b b expression b member this Item with get b index b b expression b member this Item with set b index value b b expressionCOBOL Cobra b pro b index b as b type b as b type br kbd class keyboard key nowrap Tab kbd b get b br kbd class keyboard key nowrap Tab kbd kbd class keyboard key nowrap Tab kbd instructions br kbd class keyboard key nowrap Tab kbd kbd class keyboard key nowrap Tab kbd b return b value br kbd class keyboard key nowrap Tab kbd b set b br kbd class keyboard key nowrap Tab kbd kbd class keyboard key nowrap Tab kbd instructions b get b index b as b type b as b type br kbd class keyboard key nowrap Tab kbd instructions br kbd class keyboard key nowrap Tab kbd b return b value b set b index b as b type b as b type br kbd class keyboard key nowrap Tab kbd instructionsType casts edit downcast upcastABAP Objects C b operator b returntype b b instructions b b C b static explicit operator b returntype b b type operand b b instructions b b b static implicit operator b returntype b b type operand b b instructions b b D T b opCast b T b if is b T b b type b b instructions b b eC b property b T b get return b conversion code b b Java Objective CEiffel 37 PythonVisual Basic NET b Shared Narrowing Operator CType b operand b As b type b As b returntype b br b instructions b br End Operator b b Shared Widening Operator CType b operand b As b type b As b returntype b br b instructions b br End Operator b PHP PerlRaku b multi method b type b b self b b b is export b instructions b b Ruby Windows PowerShellOCamlF COBOL Member access editHow to access members of an object x object member class member namespace membermethod field propertyABAP Objects b x gt b method b b parameters b b 41 b x gt b field b x gt b field or b x gt b method b b parameters sup id cite ref abapparam 41 1 class reference a href cite note abapparam 41 41 a sup b b C b x b method b b parameters b b or br b ptr gt b method b b parameters b b b x b field or br b ptr gt b field cls b b member ns b b memberObjective C b x b method b b parameter bar b b parameter b b b x gt b field b x b property 2 0 only or br b x b property b b b b cls method b b parameter bar b b parameter b b Smalltalk b x b method b b parameter bar b b parameter cls method b b parameter bar b b parameter Swift b x b method b b parameters b b b x b property cls b b memberAPL Dyalog left argument b x b method right argument s b x b field b x b property cls b b member ns b b memberC b x b method b b parameters b b Java D b x b propertyPythonVisual Basic NETXojoWindows PowerShell b b cls b b memberF cls b b membereC b x b method b b parameters b b b x b field b x b property cls b b member ns b b memberEiffel b x b method b b parameters b b b x b field b b cls b b member Ruby b x b property cls b b memberPHP b x gt b method b b parameters b b b x gt b field b x gt b property cls b b member ns b b memberPerl b x gt b method b b parameters b b b x gt b field b b cls b gt b method b b parameters b b ns b b memberRaku b x b method b b parameters b b or br b x b method b b parameters b b b x b field or br b x b field cls b b method b b parameters b b or br cls b b method b b parameters b b ns b b memberOCaml b x b method parameters JavaScript b x b method b b parameters b b br b x b method b b parameters b b b x b field br b x b field b x b property br b x b property b cls b member br b cls b member COBOL b INVOKE x b b b method b b b USING b parameters b RETURNING b result or br b x b method b b b b parameters b b property b OF x b b INVOKE b cls b b method b b b USING b parameters b RETURNING b result or br cls b b method b b b b parameters b b or br property b OF b cls Cobra b x b method b b parameters b b b x b field b x b property cls b b member ns b b memberMember availability editHas member Handler for missing memberMethod Field Method FieldAPL Dyalog b 3 x NC b method b b b 2 x NC b method b b ABAP Objects C Objective C Cocoa b b x b respondsToSelector selector b method b b forwardInvocation Smalltalk x b respondsTo b selector doesNotUnderstand C using reflection eCJavaD opDispatch Eiffel Python b hasattr b x b b method b and callable b x b b method b b b hasattr b x b b field b b getattr Visual Basic NET using reflection Xojo using Introspection Windows PowerShell using reflection F using reflection Ruby x b respond to b method b b method missing PHP b method exists b x b b method b b b property exists b x b b field b b call get set Perl x b gt can b method b b b exists b x b gt b field b b AUTOLOADRaku x b can b method b b x b b field b defined b AUTOLOADOCaml JavaScript b a href Typeof html title Typeof typeof a b x b b method b function b field b in b xCOBOL Special variables editcurrent object current object s parent object null reference Current Context of ExecutionSmalltalk b self b b super b b nil b b thisContext b ABAP Objects b me b b super b b initial b APL Dyalog b THIS b b BASE b b NULL b C b this b 42 b NULL b b nullptr b C b this b b base b 43 b null b Java b super b 43 DJavaScript b super b 43 ECMAScript 6 b null b b undefined b 44 eC b this b b null b Objective C b self b b super b 43 b nil b Swift b self b b super b 43 b nil b 45 Python b self b 46 b super b current class name b self b 7 b super b 3 x only b None b Visual Basic NET b Me b b MyBase b b Nothing b Xojo b Me Self b b Parent b b Nil b Eiffel b Current b b Precursor b b b superclass b b b b args b b 43 47 b Void b PHP b this b b parent b 43 b null b Perl b self b 46 b self gt SUPER b 43 b undef b Raku b self b b SUPER b b Nil b Ruby b self b b super b b b args b b 48 b nil b b binding b Windows PowerShell b this b b NULL b OCaml b self b 49 b super b 50 51 F b this b b base b 43 b null b COBOL b SELF b b SUPER b b NULL b Cobra b this b b base b b nil b Special methods editString representation Object copy Value equality Object comparison Hash code Object IDHuman readable Source compatibleABAP Objects APL Dyalog b b x b SRC b x b NS b x x b b y C x b b y 52 pointer to object can be converted into an integer IDC x b ToString b x b Clone b x b Equals b y b b x b CompareTo b y b b x b GetHashCode b b System wbr wbr Runtime wbr wbr CompilerServices wbr wbr RuntimeHelpers wbr wbr GetHashCode b x b b Java x b toString b x b a href Clone Java method html title Clone Java method clone a b 53 x b equals b y b b x b compareTo b y b b 54 x b hashCode b b System wbr wbr identityHashCode wbr wbr b x b b JavaScript x b toString b D x b toString b or br b std conv wbr wbr to string wbr wbr b x b b x b stringof b x b b y or br x b opEquals b y b b x b opCmp b y b b x b toHash b eC x b OnGetString tempString null null b or br b PrintString b x b b y b OnCopy b x b b x b OnCompare b y b b object handle can be converted into an integer IDObjective C Cocoa x b description b x b debugDescription b b b x b copy b 55 b b x b isEqual b y b b b b x b compare b y b b 56 x b hash b pointer to object can be converted into an integer IDSwift x b description b 57 x b debugDescription b 58 x b b y 59 x b lt b y 60 x b hashValue b 61 b reflect b x b wbr wbr objectIdentifier wbr wbr uintValue b Smalltalk x b displayString b x b printString b x b copy b x b b y x b hash b x b identityHash b Python b str b x b b 62 b repr b x b b 63 b copy copy b x b b 64 x b b y 65 b cmp b x b b y b b 66 b hash b x b b 67 b id b x b b Visual Basic NET x b ToString b x b Clone b x b Equals b y b b x b CompareTo b y b b x b GetHashCode b Eiffel x b out b x b twin b x b is equal b y b b When x is b COMPARABLE b one can simply do x b lt b y When x is b HASHABLE b one can use x b hash code b When x is b IDENTIFIED b one can use x b object id b PHP b x gt toString b b clone b x 68 x b b y b spl object hash b x b b Perl b b x b b 69 b Data Dumper wbr wbr gt Dump wbr wbr b x b b span class nowrap style padding left 0 1em span x span class nowrap style padding left 0 1em span b b 70 b Storable wbr wbr dclone wbr wbr b x b b 71 b Scalar wbr wbr Util wbr wbr refaddr wbr wbr b x b b 72 Raku b b x 69 x b perl b x b clone b x b eqv b y x b cmp b y x b WHICH b Ruby x b to s b x b inspect b x b dup b or br x b clone b x b b y or br x b eql b y b b x b lt gt b y x b hash b x b object id b Windows PowerShell x b ToString b x b Clone b x b Equals b y b b x b CompareTo b y b b x b GetHashCode b OCaml b Oo copy b x x b b y b Hashtbl wbr wbr hash b x b Oo id b xF b string b x or x b wbr wbr ToString b or b sprintf O b x b sprintf A b x x b Clone b x b b y or x b wbr wbr Equals b y b b b compare b x y or x b wbr wbr CompareTo b y b b b hash b x or x b wbr wbr GetHashCode b COBOL Type manipulation editGet object type Is instance of includes subtypes Upcasting DowncastingRuntime check No checkABAP Objects 73 C b a href Typeid html class mw redirect title Typeid typeid a b x b b b a href Dynamic cast html class mw redirect title Dynamic cast dynamic cast a lt b type b gt amp b x b a href Null pointer html title Null pointer nullptr a b 74 b a href Dynamic cast html class mw redirect title Dynamic cast dynamic cast a lt b type b gt b ptr b b b b type b b ptr or br b static cast lt b type b gt b ptr b b C x b GetType b x b is b type b b type b b x or x b as b typeD b typeid b x b b b cast b type b b xDelphi x b is b type x b as b typeeC x b class b b eClass IsDerived x class b type b b b b type b b xJava x b getClass b x b instanceof b class b b type b b xObjective C Cocoa b b x b class b 75 b b x b isKindOfClass b class b class b b b type b b xSwift x b dynamicType b x b is b type x b as b type x b as b typeJavaScript x b constructor b small If not rewritten small x b instanceof b class 76 Visual Basic NET x b GetType b b a href Typeof html title Typeof TypeOf a b x b Is b type 74 b CType b x b b type b b or b TryCast b x b b type b b Xojo b Introspection GetType x b x b IsA b type b CType b x b b type b b Eiffel x b generating type b b attached TYPE b x b attached TYPE b x b as b down xPython b type b x b b b isinstance b x b b type b b 76 PHP b get class b x b b x b instanceof b classPerl b ref b x b b x b gt isa b class b b Raku x b WHAT b x b isa b class b b 74 type b b x b b or br x b b typeRuby x b class b x b instance of b type b b or br x b kind of b type b b 76 Smalltalk x b class b x b isKindOf b classWindows PowerShell x b GetType b x b is b type b b 74 b b type b b x or x b as b type b b OCaml 77 b b x b gt b type b b F x b GetType b x b b type b b x b gt b type b b COBOL x b AS b type 74 Namespace management editImport namespace Import itemqualified unqualifiedABAP ObjectsC b using namespace b ns b b b using b ns item b b C b using b ns b b b using b item b b ns b b item b b D b import b ns b b b import b ns b b item b b Java b import b ns b b b import b ns b b item b b Objective CVisual Basic NET b Imports b nsEiffelPython b import b ns b from b ns b import b b from b ns b import b itemPHP b use b ns b b b use b ns b b item b b Perl b use b ns b b b use b ns qw item b b RakuRubyWindows PowerShellOCaml b open b nsF COBOL Contracts editPrecondition Postcondition Check Invariant LoopABAP Objects C C i Spec i br type foo b b parameters b b br b requires b expression br br body br i Spec i br type foo b b parameters b b br b ensures b expression br br body br Java Objective CVisual Basic NETD f br b in b asserts b br body b instructions b b f br b out b result b b asserts b br body b instructions b b b assert b expression b b b invariant b expression b b Eiffel f br b require b tag expression br b do end b f br b do br ensure b tag expression br b end b f br b do b br b check b tag expression b end br end b b class b X br b invariant b tag expression br b end b b from b instructions br b invariant b br tag expression br b until b br expr br b loop b br instructions br b variant b br tag expression br b end b Python PHPPerlRaku b PRE b condition b b b POST b condition b b Ruby Windows PowerShellOCamlF COBOLSee also editObject oriented programmingReferences and notes edit parameter argument may be repeated if the constructor has several parameters SAP reserved to himself the use of destruction a b c d e f g h i j k l This language uses garbage collection to release unused memory This syntax creates an object value with automatic storage duration This syntax creates an object with dynamic storage duration and returns a pointer to it OCaml objects can be created directly without going through a class a b c d e f g This language supports multiple inheritance A class can have more than one parent class Not providing a parent class makes the class a root class In practice this is almost never done One should generally use the conventional base class of the framework one is using which is NSObject for Cocoa and GNUstep or Object otherwise Usually the interface portion is placed into a header file and the interface portion is placed into a separate source code file Prefixes to class and protocol names conventionally used as a kind of namespace In Python interfaces are classes which methods have pass as their bodies The class is an Object Just send a message to the superclass st 80 or the destination namespace Visualworks The namespace is an Object Just send a message to the parent namespace A finalizer is called by the garbage collector when an object is about to be garbage collected There is no guarantee on when it will be called or if it will be called at all In ABAP the constructor is to be defined like a method see comments about method with the following restrictions the method name must be constructor and only importing parameters can be defined An optional comma separated list of initializers for member objects and parent classes goes here The syntax for initializing member objects is member name b b parameters b b This works even for primitive members in which case one parameter is specified and that value is copied into the member The syntax for initializing parent classes is class name b b parameters b b If an initializer is not specified for a member or parent class then the default constructor is used Any Eiffel procedure can be used as a creation procedure aka constructors See Eiffel paragraph at Constructor computer science Implementing DISPOSABLE dispose ensures that dispose will be called when object is garbage collected This initializer construct is rarely used Fields in OCaml are usually initialized directly in their declaration Only when additional imperative operations are needed is initializer used The parameters to the constructor in other languages are instead specified as the parameters to the class in OCaml See the class declaration syntax for more details This syntax is usually used to overload constructors In JavaScript constructor is an object Constructors can be emulated with a factory method returning a class instance a b c Scope identifier must appear once in the file declaration all variable declarations after this scope identifier have his scope until another scope identifier or the end of class declaration is reached In ABAP specific fields or methods are not declared as accessible by outside things Rather outside classes are declared as friends to have access to the class s fields or methods In C specific fields are not declared as accessible by outside things Rather outside functions and classes are declared as friends to have access to the class s fields See friend function and friend class for more details Just send a message to the class class addInstVarName field class removeInstVarName field a b c d Just assign a value to it in a method Python doesn t have private fields all fields are publicly accessible at all times A community convention exists to prefix implementation details with one underscore but this is unenforced by the language All class data is private because the COBOL standard does not specify any way to access it The declaration and implementation of methods in ABAP are separate methods statement is to be used inside the class definition method without s is to be used inside the class implementation parameter argument can be repeated if there are several parameters In ABAP the return parameter name is explicitly defined in the method signature within the class definition In C declaring and implementing methods is usually separate Methods are declared in the class definition which is usually included in a header file using the syntax Although the body of a method can be included with the declaration inside the class definition as shown in the table here this is generally bad practice Because the class definition must be included with every source file which uses the fields or methods of the class having code in the class definition causes the method code to be compiled with every source file increasing the size of the code Yet in some circumstances it is useful to include the body of a method with the declaration One reason is that the compiler will try to inline methods that are included in the class declaration so if a very short one line method occurs it may make it faster to allow a compiler to inline it by including the body along with the declaration Also if a template class or method occurs then all the code must be included with the declaration because only with the code can the template be instantiated a b Just assign a function to it in a method Alternative implementation def bar doc The bar property def fget self return self bar def fset self value self bar value return locals bar property bar these examples need the Class Accessor module installed a b c Although Eiffel does not support overloading of operators it can define operators PHP does not support operator overloading natively but support can be added using the operator PECL package The class must implement the ArrayAccess interface The class must overload array dereference or subclass one of Tie Array or Tie StdArray to hook array operations a b In ABAP arguments must be passed using this syntax b x gt b method b b b exporting b parameter argument b importing b parameter argument b changing b parameter argument b returning value b parameter b b b parameter argument b can be repeated if there are several parameters C doesn t have a super keyword because multiple inheritance is possible and so it may be ambiguous which base class is referenced Instead the BaseClassName 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 a b c d e f g h i The keyword here is not a value and it can only be used to access a method of the superclass But be afraid they have not the same value only for Optional types a b In this language instance methods are passed the current object as the first parameter which is conventionally named self but this is not required to be the case Precursor in Eiffel is actually a call to the method of the same name in the superclass So Precursor args is equivalent to super currentMethodName args in Java There is no way of calling a method of different name in the superclass super in Ruby unlike in other languages is actually a call to the method of the same name in the superclass So super args in Ruby is equivalent to super currentMethodName args in Java There is no way of calling a method of different name in the superclass In OCaml an object declaration can optionally start with a parameter which will be associated with the current object This parameter is conventionally named self but this is not required to be the case It is good practice to put a parameter there so that one can call one s own methods In OCaml an inheritance declaration inherit can optionally be associated with a value with the syntax inheritparent class parameters as super Here super is the name given to the variable associated with this parent object It can be named differently However if the ability to have an optional value in OCaml is needed then wrap the value inside an 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 assuming that x and y are the objects and not pointers Can be customized by overloading the object s operator Only accessible from within the class since the 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 The class should implement the interface Comparable for this method to be standardized Implemented by the object s copyWithZone method compare is the conventional name for the comparison method in Foundation classes However no formal protocol exists Only if object conforms to the Printable protocol Only if object conforms to the DebugPrintable protocol Only if object conforms to the Equatable protocol Only if object conforms to the Comparable protocol Only if object conforms to the hashValue protocol Can be customized by the object s str method Can be customized by the object s repr method Can be customized by the object s copy method Can be customized by the object s eq method Only in Python 2 x and before removed in Python 3 0 Can be customized by the object s cmp method Can be customized by the object s hash method Not all types are hashable mutable types are usually not hashable Can be customized by the object s clone method a b Can be customized by overloading the object s string conversion operator This example requires useing Data Dumper This example requires useing Storable This example requires useing Scalar Util Run time type information in ABAP can be gathered by using different description Classes like CL ABAP CLASSDESCR a b c d e Upcasting is implicit in this language A subtype instance can be used where a supertype is needed Only for non class objects If 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 a b c This language is dynamically typed Casting between types is unneeded This language doesn t give run time type information It is unneeded because it is statically typed and downcasting is impossible Retrieved from https en wikipedia org w index php title Comparison of programming languages object oriented programming amp oldid 1177167134, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.