Este artículo puede requerir una limpieza para cumplir con los estándares de calidad de Wikipedia . El problema específico es: La sección de referencia de este artículo contiene muchas notas a pie de página, pero no incluye referencias o fuentes externas. ( Junio de 2013 ) |
Esta comparación de lenguajes de programación compara cómo los lenguajes de programación orientados a objetos como C++ , Java , Smalltalk , Object Pascal , Perl , Python y otros manipulan las estructuras de datos .
construcción | destrucción | |
---|---|---|
Objetos ABAP | data variable type ref to class . [1] | [2] [3] |
APL (dialog) | variable←⎕NEW class «parameters» | ⎕EX 'variable' |
C++ | class variable«(parameters)»; [4] o [5]class *variable = new class«(parameters)»; | delete pointer; |
DO# | class variable = new class(parameters); | variable.Dispose(); [3] |
Java | [3] | |
D | destroy(variable); | |
CE | class «instance handle» { «properties/data members assignments, instance method overrides» } | delete instance handle; |
Objetivo-C ( Cacao ) | class *variable = [[class alloc ] init]; oclass *variable = [[class alloc ] initWithFoo:parameter «bar:parameter ...»]; | [variable release]; |
Rápido | let variable = class(parameters) | |
Pitón | variable = class(parameters) | del variable [3] (Normalmente no es necesario) |
Visual Basic .NET | Dim variable As New class(parameters) | variable.Dispose() [3] |
Xojo | Dim variable As New class(parameters) | variable = Nil |
Torre Eiffel | create variable o o ocreate «{TYPE}» variable.make_foo «(parameters)» variable := create {TYPE} 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; |
Rubí | variable = class.new«(parameters)» | [3] |
Windows PowerShell | $variable = New-Object «-TypeName» class ««-ArgumentList» parameters» | Remove-Variable «-Name» variable |
OCaml | let variable = new class «parameters» o [6]let variable = object members end | [3] |
F# | let variable = «new »class(«parameters») | |
Charla informal | La clase es un objeto. Simplemente envíe un mensaje a una clase, generalmente #new o #new: y muchos otros, por ejemplo:Punto x: 10 y: 20 . Matriz con: -1 con: 3 con: 2 . | |
JavaScript | var variable = new class«(parameters)» ovar variable = { «key1: value1«, key2: value2 ...»»} | [3] |
Objeto Pascal ( Delphi ) | ClassVar := ClassType.ConstructorName(parameters); | ClassVar.Free; |
Escala | val obj = new Object // sin parámetros val obj = new Object ( arg0 , arg1 , arg2 ...) val obj = Object ( arg0 , arg1 , arg2 ...) // clase de caso val obj = new Object ( arg0 , arg1 , param1 = value1 , ...) // parámetros nombrados | [3] |
COBOL | INVOKE class "NEW" RETURNING variable oMOVE 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] |
clase | protocolo | espacio de nombres | |
---|---|---|---|
Objetos ABAP | class name definition «inheriting from parentclass». «interfaces: interfaces.» method_and_field_declarations endclass. | interface name. members endinterface. | — |
APL (dialog) | :Class name «:parentclass» «,interfaces» members :EndClass | :Interface name members :EndInterface | :Namespace name members :EndNamespace |
C++ | class name« : public parentclasses [7]» { members }; | namespace name { members } | |
DO# | class name« : «parentclass»«, interfaces»» { members } | interface name« : parentinterfaces» { members } | |
D | module name; | ||
CE | 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 | ||
Objetivo-C | @interface name« : parentclass» [8] [9]«< protocols >» { instance_fields } method_and_property_declarations @end | @protocol name«< parentprotocols >» members @end | [10] |
Rápido | class name« : «parentclass»«, protocols»» { members } | protocol name« : parentprotocols» { members } | |
Pitón | class name«(parentclasses[7])»: | [11] | __all__ = [ member1,member2,... ] |
Visual Basic .NET | Class name« Inherits parentclass»« Implements interfaces» | Interface name« Inherits parentinterfaces» | Namespace name |
Xojo | Class name« Inherits parentclass»« Implements interfaces» | Interface name« Inherits parentinterfaces» | Module name |
Torre Eiffel | class name« inherit parentclasses[7]» | — | |
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 } |
Rubí | class name« < parentclass» | module name | |
Windows PowerShell | — | ||
OCaml | class name «parameters» = object «(self)» «inherit parentclass «parameters» «inherit parentclass «parameters» ...[7]»» members end | module name | |
F# | type name«(parameters)» «as this» = class «inherit parentclass«(parameters)» «as base»» members «interface interface with implementation «interface interface with implementation ...»» end | type name = interface members end | namespace name |
Charla informal | [12] | [13] | |
JavaScript (ES6) | class name «extends parentclass» { members } | ||
Objeto Pascal (Delphi) |
| package name; members | |
Escala | clase ConcreteClass ( params del constructor ) extiende ParentClass con Trait1 con Trait2 con Trait2 { // miembros } | rasgo TraitName extiende OtherTrait1 con OtherTrait2 con OtherTrait3 { // miembros } | nombre del paquete |
COBOL | CLASS-ID. name« INHERITS« FROM» parentclasses». FACTORY« IMPLEMENTS interfaces». class-members END FACTORY. OBJECT« IMPLEMENTS interfaces». instance-members END OBJECT.
| INTERFACE-ID. name« INHERITS« FROM» interfaces». members
| — |
Cobra | class name «inherits parentclass» «implements interfaces» | interface name «inherits parentinterfaces» | namespace name |
ISLISP | (defclass name (base-class) ((x :initform 0 :accessor get-x :initarg x)) (:abstractp nil)) |
constructor | incinerador de basuras | finalizador [14] | |
---|---|---|---|
Objetos ABAP | methods constructor «importing parameter = argument» [15] | — | |
APL (dialog) | ∇ name :Implements Constructor «:Base «expr»» instructions ∇ | ∇ name :Implements Destructor instructions ∇ | |
C++ | class(«parameters») «: initializers [16]» { instructions } | ~class() { instructions } | |
DO# | class(«parameters») { instructions } | void Dispose(){ instructions } | ~class() { instructions } |
D | this(«parameters») { instructions } | ~this() { instructions } | |
CE | class() { instructions } | ~class() { instructions } | |
Java | class(«parameters») { instructions } | void finalize() { instructions } | |
Torre Eiffel | [17] | [18] | |
Objetivo-C (Cacao) | - (id)init { instructions... return self; } or | - (void)dealloc { instructions } | - (void)finalize { instructions } |
Rápido | init(«parameters») { instructions } | deinit { instructions } | |
Pitón | def __init__(self«, parameters»): | def __del__(self): | |
Visual Basic .NET | Sub New(«parameters») | Sub Dispose() | Overrides Sub Finalize() |
Xojo | Sub Constructor(«parameters») | Sub Destructor() | |
PHP | function __construct(«parameters») { instructions } | function __destruct() { instructions } | |
Perl | sub new { my ($class«, parameters») = @_; my $self = {}; instructions ... bless($self, $class); return $self; } | sub DESTROY { my ($self) = @_; instructions } | |
Raku | submethod BUILD { instructions } or | submethod DESTROY { instructions } | |
Rubí | def initialize«(parameters)» | — | |
Windows PowerShell | — | ||
OCaml | initializer instructions [19] | — | |
F# | do instructions or [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) | def dispose | |
ISLISP | (defmethod initialize-object ((instance <class-name>) initvalues) |
público | privado | protegido | amigo | |
---|---|---|---|---|
Objetos ABAP | public section.[23] data field type type. | private section.[23] data field type type. | protected section.[23] data field type type. | [24] |
APL (dialog) | :Field Public field «← value» | :Field «Private» field «← value» | ||
C++ | public: type field; | private: type field; | protected: type field; | [25] |
DO# | 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»; | ||
CE | public type field; | private type field; | ||
Torre Eiffel | feature | feature {NONE} | feature {current_class} | feature {FRIEND} |
Objetivo-C | @public type field; | @private type field; | @protected type field; | @package type field; |
Rápido | — | |||
Charla informal | — | [26] | — | |
Pitón | 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 | — | |
Rubí | — | @field = value [27] | ||
Windows PowerShell | Add-Member | — | ||
OCaml | — | val «mutable» field = value | — | |
F# | — | let «mutable» field = value | — | |
JavaScript | this.field = value [27] | |||
COBOL | — | cláusulas de campo de número de nivel . [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) |
método básico/vacío | método de retorno de valor | ||
---|---|---|---|
Objetos ABAP | methods name «importing parameter = argument» «exporting parameter = argument» «changing parameter = argument» «returning value(parameter)» [30] | [31] | |
APL (dialog) | ∇ «left argument» name «right arguments» instructions ∇ | ∇ result ← «left argument» name «right arguments» instructions ∇ | |
C++ [32]
La implementación de métodos generalmente se proporciona en un archivo fuente separado, con la siguiente sintaxis
| void foo(«parameters») { instructions } | type foo(«parameters») { instructions ... return value; } | |
DO# | |||
D | |||
Java | |||
CE | void ««type of 'this'»::»foo(«parameters») { instructions } | type ««type of this»::»foo(«parameters») { instructions ... return value; } | |
Torre Eiffel | foo ( «parameters» ) | foo ( «parameters» ): TYPE | |
Objetivo-C | - (void)foo«:parameter «bar:parameter ...»» { instructions } | - (type)foo«:parameter «bar:parameter ...»» { instructions... return value; } | |
Rápido | func foo(«parameters») { instructions } | func foo(«parameters») -> type { instructions... return value } | |
Pitón | def foo(self«, parameters»): | def foo(self«, parameters»): | |
Visual Basic .NET | Sub Foo(«parameters») | Function Foo(«parameters») As type | |
Xojo | Sub Foo(«parameters») | Function Foo(«parameters») As type | |
PHP | function foo(«parameters»)«: void» { instructions } | function foo(«parameters»)«: type» { instructions ... return value; } | |
Perl | sub foo { my ($self«, parameters») = @_; instructions } | sub foo { my ($self«, parameters») = @_; instructions ... return value; } | |
Raku | «has »«multi »method foo(««$self: »parameters») { instructions } | «has «type »»«multi »method foo(««$self: »parameters») { instructions ... return value; } | |
Rubí | def foo«(parameters)» | def foo«(parameters)» | |
Windows PowerShell | Add-Member «-MemberType» ScriptMethod «-Name» foo «-Value» { «param(parameters)» instructions } -InputObject variable | Add-Member «-MemberType» ScriptMethod «-Name» foo «-Value» { «param(parameters)» instructions ... return value } -InputObject variable | |
OCaml | — | method foo «parameters» = expression | |
F# | member this.foo(«parameters») = expression | ||
JavaScript | this.method = function(«parameters») {instructions} [34] | this.method = function(«parameters») {instructions... return value;} [34] | |
Javascript (ES6) | foo(«parameters») {instructions} | foo(«parameters») {instructions... return value;} | |
COBOL | METHOD-ID. foo. instructions
| METHOD-ID. foo. instructions
| |
Cobra | def foo(parameters) | def foo(parameters) as type | |
ISLISP | (defgeneric method (arg1 arg2)) |
Cómo declarar una propiedad denominada "Bar"
lectura-escritura | Sólo lectura | Sólo escritura | |
---|---|---|---|
Objetos ABAP | — | ||
APL (dialog) | :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++ | — | ||
DO# | type Bar { | type Bar { get { instructions ... return value; } } | type Bar { set { instructions } } |
D | @property type bar() { instructions ... return value; } | @property type bar() { instructions ... return value; } | @property type bar(type value) { instructions ... return value; } |
CE | property type Bar { | property type Bar { get { instructions ... return value; } } | property type Bar { set { instructions } } |
Java | — | ||
Objective-C 2.0 (Cacao) | @property (readwrite) type bar; Y luego dentro@implementation | @property (readonly) type bar; Y luego dentro@implementation | — |
Rápido | var bar : type { get { instructions } set«(newBar)» { instructions } } | var bar : type { instructions } | — |
Torre Eiffel | feature -- Access | ||
Pitón | def setBar(self, value): [35] | def getBar(self): | def setBar(self, value): |
Visual Basic .NET | Property Bar() As type | ReadOnly Property Bar() As type | WriteOnly Property Bar() As type |
Xojo | ComputedProperty Bar() As type | ComputedProperty Bar() As type | ComputedProperty Bar() As type |
PHP | function __get($property) { | function __get($property) { | function __set($property, $value) { |
Perl | sub Bar { | sub Bar { | sub Bar { |
Raku | — | ||
Rubí | def bar | def bar | def bar=(value) |
Windows PowerShell | Add-Member | Add-Member | Add-Member |
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. instructions
instructions
| METHOD-ID. GET PROPERTY bar. instructions
| METHOD-ID. SET PROPERTY bar. instructions
|
Cobra | pro bar «as type» | get bar «as type» | set bar «as type» |
ISLISP | — |
lectura-escritura | Sólo lectura | Sólo escritura | |
---|---|---|---|
Objetos ABAP | — | ||
C++ | — | ||
DO# | type Bar { get; set; } | type Bar { get; private set; } | type Bar { private get; set; } |
D | — | ||
Java | — | ||
Objective-C 2.0 (Cacao) | @property (readwrite) type bar; Y luego dentro@implementation | @property (readonly) type bar; Y luego dentro@implementation | — |
Rápido | var bar : type | let bar : type | — |
Torre Eiffel | |||
Pitón | @property | @property | bar = property() |
Visual Basic .NET | Property Bar As type« = initial_value» (VB 10) | ||
PHP | |||
Perla [36] | use base qw(Class::Accessor); | use base qw(Class::Accessor); | use base qw(Class::Accessor); |
Raku | — | ||
Rubí | 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» |
unario | binario | llamada de función | |
---|---|---|---|
Objetos ABAP | — | ||
C++ | type operator symbol () { instructions } | type operator symbol (type operand2) { instructions } | type operator () («parameters») { instructions } |
DO# | 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 opCall(«parameters») { instructions } |
Java | — | ||
Objetivo-C | |||
Rápido | func symbol(operand1 : type) -> returntype { instructions } (fuera de clase) | func symbol(operand1 : type1, operand2 : type2) -> returntype { instructions } (fuera de clase) | |
Eiffel [37] | op_name alias "symbol": TYPE | op_name alias "symbol" (operand: TYPE1): TYPE2 | |
Pitón | def __opname__(self): | def __opname__(self, operand2): | def __call__(self«, parameters»): |
Visual Basic .NET | Shared Operator symbol(operand As type) As type | Shared Operator symbol(operand1 As type, operand2 As type) As type | — |
Xojo | Function Operator_name(operand As type) As type | — | |
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 infix:<symbol> («$operand1: » type operand2) { instructions ... return value; } | «our «type »»«multi »method postcircumfix:<( )> («$self: » «parameters») { instructions } |
Rubí | def symbol | def symbol(operand2) | — |
Windows PowerShell | — | ||
OCaml | |||
F# | static member (symbol) operand = expression | static member (symbol) (operand1, operand2) = expression | — |
COBOL | — | ||
ISLISP | — |
lectura-escritura | Sólo lectura | Sólo escritura | |
---|---|---|---|
Objetos ABAP | — | ||
APL (dialog) | :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 } | |
DO# | type this[type index] { | type this[type index] { get{ instructions } } | type this[type index] { set{ instructions } } |
D | type opIndex(type index) { instructions } | type opIndex(type index) { instructions } | type opIndexAssign(type value, type index) { instructions } |
Java | — | ||
Objective-C (compilador reciente de Clang) | — | - (id)objectAtIndexedSubscript:(NSUInteger)index { instructions return value; } or | - (void)setObject:(id)value atIndexedSubscript:(NSUInteger)index { instructions } or |
Rápido | 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 | bracket_name alias "[]" (index: TYPE): TYPE | |
Pitón | def __getitem__(self, index): | def __getitem__(self, index): | def __setitem__(self, index, value): |
Visual Basic .NET | Default Property Item(Index As type) As type | Default ReadOnly Property Item(Index As type) As type | Default WriteOnly Property Item(Index As type) As type |
PHP | [39] | ||
Perl | [40] | ||
Raku | «our «type »»«multi »method postcircumfix:<[ ]> is rw («$self: » type $index) { instructions ... return value; } or | «our «type »»«multi »method postcircumfix:<[ ]>(«$self: » type $index) { instructions ... return value; } or | — |
Rubí | def [](index) | def [](index) | def []=(index, value) |
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 | get[index «as type»] as type | set[index «as type»] as type |
alicaído | subida de tono | |
---|---|---|
Objetos ABAP | — | |
C++ | operator returntype() { instructions } | |
DO# | static explicit operator returntype(type operand) { instructions } | static implicit operator returntype(type operand) { instructions } |
D | T opCast(T)() if (is(T == type)) { instructions } | |
CE | property T { get { return «conversion code»; } } | |
Java | — | |
Objetivo-C | ||
Eiffel [37] | ||
Pitón | ||
Visual Basic .NET | Shared Narrowing Operator CType(operand As type) As returntype | Shared Widening Operator CType(operand As type) As returntype |
PHP | — | |
Perl | ||
Raku | multi method type«($self:)» is export { instructions } | |
Rubí | — | |
Windows PowerShell | ||
OCaml | ||
F# | ||
COBOL | — |
Cómo acceder a los miembros de un objeto x
miembro del objeto | miembro de la clase | miembro del espacio de nombres | |||
---|---|---|---|---|---|
método | campo | propiedad | |||
Objetos ABAP | x->method(«parameters»). [41] | x->field | — | x=>field or x=>method(«parameters[41]»). | — |
C++ | x.method(parameters) or | x.field or | cls::member | ns::member | |
Objetivo-C | [x method«:parameter «bar:parameter ...»»] | x->field | x.property (2.0 only) or | [cls method«:parameter «bar:parameter ...»»] | |
Charla informal | x method«:parameter «bar:parameter ...»» | — | cls method«:parameter «bar:parameter ...»» | ||
Rápido | x.method(parameters) | x.property | cls.member | ||
APL (dialog) | left argument» x.method «right argument(s)» | x.field | x.property | cls.member | ns.member |
DO# | x.method(parameters) | ||||
Java | — | ||||
D | x.property | ||||
Pitón | |||||
Visual Basic .NET | |||||
Xojo | |||||
Windows PowerShell | [cls]::member | ||||
F# | — | cls.member | |||
CE | x.method«(parameters)» | x.field | x.property | cls::member | ns::member |
Torre Eiffel | x.method«(parameters)» | x.field | {cls}.member | — | |
Rubí | — | x.property | cls.member | ||
PHP | x->method(parameters) | x->field | x->property | cls::member | ns\member |
Perl | x->method«(parameters)» | x->{field} | cls->method«(parameters)» | ns::member | |
Raku | x.method«(parameters)» or | x.field or | cls.method«(parameters)» or | ns::member | |
OCaml | x#method «parameters» | — | |||
JavaScript | x.method(parameters) | x.field | x.property | cls.member | — |
COBOL | INVOKE x "method" «USING parameters» «RETURNING result» or | — | property OF x | INVOKE cls "method" «USING parameters» «RETURNING result» or | — |
Cobra | x.method«(parameters)» | x.field | x.property | cls.member | ns.member |
¿Tiene miembro? | Controlador de miembros faltantes | |||
---|---|---|---|---|
Método | Campo | Método | Campo | |
APL (dialog) | 3=x.⎕NC'method' | 2=x.⎕NC'method' | — | |
Objetos ABAP | — | |||
C++ | ||||
Objetivo-C (Cacao) | [x respondsToSelector:@selector(method)] | — | forwardInvocation: | — |
Charla informal | x respondsTo: selector | — | doesNotUnderstand: | — |
DO# | (usando la reflexión) | |||
CE | ||||
Java | ||||
D | opDispatch() | |||
Torre Eiffel | — | |||
Pitón | hasattr(x, "method") and callable(x.method) | hasattr(x, "field") | __getattr__() | |
Visual Basic .NET | (usando la reflexión) | |||
Xojo | (usando introspección) | |||
Windows PowerShell | (usando la reflexión) | |||
F# | (usando la reflexión) | |||
Rubí | 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} | CARGA AUTOMÁTICA | |
Raku | x.can("method") | x.field.defined | CARGA AUTOMÁTICA | |
OCaml | — | |||
JavaScript | typeof x.method === "function" | field in x | ||
COBOL | — |
objeto actual | objeto padre del objeto actual | referencia nula | Contexto actual de ejecución | |
---|---|---|---|---|
Charla informal | self | super | nil | thisContext |
Objetos ABAP | me | super | initial | |
APL (dialog) | ⎕THIS | ⎕BASE | ⎕NULL | |
C++ | *this | [42] | NULL, nullptr | |
DO# | this | base [43] | null | |
Java | super [43] | |||
D | ||||
JavaScript | super [43] (ECMAScript 6) | null, undefined [44] | ||
CE | this | null | ||
Objetivo-C | self | super [43] | nil | |
Rápido | self | super [43] | nil [45] | |
Pitón | self [46] | super(current_class_name, self) [7]super() (solo 3.x) | None | |
Visual Basic .NET | Me | MyBase | Nothing | |
Xojo | Me / Self | Parent | Nil | |
Torre Eiffel | Current | Precursor «{superclass}» «(args)» [43] [47] | Void | |
PHP | $this | parent [43] | null | |
Perl | $self [46] | $self->SUPER [43] | undef | |
Raku | self | SUPER | Nil | |
Rubí | 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 |
Representación de cadenas | Copia de objeto | Igualdad de valores | Comparación de objetos | Código hash | Identificación del objeto | ||
---|---|---|---|---|---|---|---|
Legible para humanos | Compatible con la fuente | ||||||
Objetos ABAP | — | ||||||
APL (dialog) | ⍕x | ⎕SRC x | ⎕NS x | x = y | — | ||
C++ | x == y [52] | El puntero al objeto se puede convertir en un identificador entero. | |||||
DO# | x.ToString() | x.Clone() | x.Equals(y) | x.CompareTo(y) | x.GetHashCode() | System | |
Java | x.toString() | x.clone() [53] | x.equals(y) | x.compareTo(y) [54] | x.hashCode() | System | |
JavaScript | x.toString() | ||||||
D | x.toString() or | x.stringof | x == y or | x.opCmp(y) | x.toHash() | ||
CE | x.OnGetString(tempString, null, null) or | y.OnCopy(x) | x.OnCompare(y) | El identificador del objeto se puede convertir en un identificador entero | |||
Objetivo-C (Cacao) | x.description | x.debugDescription | [x copy] [55] | [x isEqual:y] | [x compare:y] [56] | x.hash | El puntero al objeto se puede convertir en un identificador entero. |
Rápido | x.description [57] | x.debugDescription [58] | x == y [59] | x < y [60] | x.hashValue [61] | reflect(x) | |
Charla informal | x displayString | x printString | x copy | x = y | x hash | x identityHash | |
Pitón | 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() | ||
Torre Eiffel | x.out | x.twin | x.is_equal(y) | Cuando x es COMPARABLE , uno puede simplemente hacerx < y | Cuando x es HASHABLE , se puede utilizarx.hash_code | Cuando x es IDENTIFIED , se puede utilizarx.object_id | |
PHP | $x->__toString() | clone x [68] | x == y |
| spl_object_hash(x) | ||
Perl | "$x" [69] | Data::Dumper [70] | Storable [71] | Scalar [72] | |||
Raku | ~x [69] | x.perl | x.clone | x eqv y | x cmp y | x.WHICH | |
Rubí | x.to_s | x.inspect | x.dup or | x == y or | x <=> y | x.hash | x.object_id |
Windows PowerShell | x.ToString() | x.Clone() | x.Equals(y) | x.CompareTo(y) | x.GetHashCode() | ||
OCaml | Oo.copy x | x = y | Hashtbl | Oo.id x | |||
F# | string x or x | sprintf "%A" x | x.Clone() | x = y or x | compare x y or x | hash x or x | |
COBOL | — |
Obtener el tipo de objeto | Es una instancia de (incluye subtipos) | Transmisión ascendente | Abatido | ||
---|---|---|---|---|---|
Comprobación del tiempo de ejecución | Sin cheque | ||||
Objetos ABAP | — [73] | = | ?= | ||
C++ | typeid(x) | dynamic_cast<type *>(&x) != nullptr | — [74] | dynamic_cast<type*>(ptr) | (type*) ptr or |
DO# | x.GetType() | x is type | (type) x or x as type | ||
D | typeid(x) | cast(type) x | |||
Delfos | x is type | x as type | |||
CE | x._class | eClass_IsDerived(x._class, type) | (type) x | ||
Java | x.getClass() | x instanceof class | (type) x | ||
Objetivo-C (Cacao) | [x class] [75] | [x isKindOfClass:[class class]] | (type*) x | ||
Rápido | 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) | — |
Torre Eiffel | x.generating_type | attached {TYPE} x | attached {TYPE} x as down_x | ||
Pitón | 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 | |
Rubí | x.class | x.instance_of?(type) or | — [76] | ||
Charla informal | 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] | — |
Importar espacio de nombres | Importar artículo | ||
---|---|---|---|
calificado | no cualificado | ||
Objetos ABAP | |||
C++ | using namespace ns; | using ns::item ; | |
DO# | using ns; | using item = ns.item; | |
D | import ns; | import ns : item; | |
Java | import ns.*; | import ns.item; | |
Objetivo-C | |||
Visual Basic .NET | Imports ns | ||
Torre Eiffel | |||
Pitón | import ns | from ns import * | from ns import item |
PHP | use ns; | use ns\item; | |
Perl | use ns; | use ns qw(item); | |
Raku | |||
Rubí | |||
Windows PowerShell | |||
OCaml | open ns | ||
F# | |||
COBOL | — |
Condición previa | Postcondición | Controlar | Invariante | Bucle | |
---|---|---|---|---|---|
Objetos ABAP | — | ||||
C++ | |||||
DO# | Spec#: | Spec#: | |||
Java | — | ||||
Objetivo-C | |||||
Visual Basic .NET | |||||
D | f | f | assert(expression) | invariant() { expression } | |
Torre Eiffel | f | f | f | class X | from instructions |
Pitón | — | ||||
PHP | |||||
Perl | |||||
Raku | PRE { condition } | POST { condition } | |||
Rubí | — | ||||
Windows PowerShell | |||||
OCaml | |||||
F# | |||||
COBOL |
NSObject
para Cocoa y GNUstep, o Object
cualquier otro.@interface
parte se coloca en un archivo de encabezado y la @interface
parte se coloca en un archivo de código fuente separado."member_name(parameters)"
"class_name(parameters)".
clase addInstVarName: campo . clase removeInstVarName: campo .
def bar (): doc = " La propiedad bar." def fget ( self ) : return self._bar def fset ( self , value ): self._bar = value return locals ( ) bar = propiedad ( ** bar ( ))
x->method(«exporting parameter = argument» «importing parameter = argument» «changing parameter = argument» «returning value(parameter)»
parameter = argument
Se puede repetir si hay varios parámetros.BaseClassName::member
sintaxis se puede utilizar para acceder a un miembro anulado en la clase base especificada. Microsoft Visual C++ proporciona una palabra clave no estándar "__super" para este propósito; pero no es compatible con otros compiladores.[1]option
tipo, cuyos valores son None
y Some x
, que podrían usarse para representar "referencia nula" y "referencia no nula a un objeto" como en otros lenguajes.==
operador del objeto.clone()
método heredado de Object
está protegido, a menos que la clase anule el método y lo haga público. Si se usa el método clone()
heredado de Object
, la clase debe implementar la Cloneable
interfaz para permitir la clonación.Comparable
para que este método esté estandarizado.copyWithZone:
método del objetocompare:
es el nombre convencional para el método de comparación en las clases Foundation. Sin embargo, no existe un protocolo formalPrintable
protocoloDebugPrintable
protocoloEquatable
protocoloComparable
protocolohashValue
protocolo__str__()
método del objeto.__repr__()
método del objeto.__copy__()
método del objeto.__eq__()
método del objeto.__cmp__()
método del objeto__hash__()
método del objeto. No todos los tipos son hasheables (los tipos mutables normalmente no lo son)__clone()
método del objeto.x
es un objeto de clase, [x class]
devuelve solo x
. El método de tiempo de ejecución object_getClass(x)
devolverá la clase de x
para todos los objetos.