(object-oriented programming)
From Wikipedia, the free encyclopedia
Jump to navigationJump to search
This article may require cleanup to meet Wikipedia's quality
standards. The specific problem is: This article's reference
sectioncontains 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)
General comparison
Assignment
Basic syntax
Basic instructions
Comments
Control flow
Foreach loops
While loops
For loops
Do-while
Exception handling
Enumerated types
Anonymous functions
Conditional expressions
Functional instructions
Arrays
Associative arrays
Scope
String operations
String functions
Higher-order functions
Type systems
List comprehension
Object-oriented programming
Object-oriented constructors
Operators
Evaluation strategy
v
t
e
Contents
construction destruction
Objects
«exporting parameter = argument». [1]
class variable«(parameters)»; or
C++ (STL) class *variable = new class«(parameters delete pointer;
)»;
variable.Dispose
C#
(); [3]
destroy(variable
D
);
class «instance
handle» { «properties/data members delete instance
eC
assignments, instance method handle;
overrides»}
Visual variable.Dispose
Dim variable As New class(parameters)
Basic .NET () [3]
create variable or
[3]
Eiffel create «{TYPE}» variable.make_foo
«(parameters)» or
variable := create {TYPE} or
variable := create {TYPE}.make_foo
«(parameters)»
unset($variable)
PHP $variable = new class«(parameters)»;
; [3]
Remove-
Windows $variable = New-Object «-TypeName»
Variable «-Name»
PowerShell class ««-ArgumentList» parameters»
variable
Point x: 10 y: 20.
Array with: -1 with: 3 with: 2.
var variable =
new class«(parameters)» or [3]
JavaScript
var variable =
{ «key1: value1«, key2: value2 ...»»}
Object ClassVar := ClassType.ConstructorName(p
Pascal(Del ClassVar.Free;
arameters);
phi)
value-2] ..])))
Class declaration[edit]
C+
+ class name« :
namespac
(ST public parentclasses [5] » { members };
e name {
L)
members
}
C#
interface name
module n
class name« : «parentclass»«, interf « :parentinter
D ame;
aces»» { members } faces»
members
{members }
package
Jav name;mem
a
interface name bers
class name« extends parentclass»« im « extendsparen
plements interfaces» { members } tinterfaces»
{members } namespac
PH e name;m
P
embers
protocol name«
Swi class name« : «parentclass»«, protoc :parentprotoc
ft ols»» { members } ols» {members
}
__all__
=
Pyt class name«(parentclasses[5])»: [9]
[member1
hon Tab ↹ members
,member2
,... ]
package
package name; «@ISA =
Perl name;mem
qw(parentclasses[5]);» members 1;
bers
role name
class name «is parentclass «does role module n
Perl [5]
«is parentclass ... »» «does role «does role ame {mem
6
«does role ...»» {members } ...»» {members bers }
}
module n
class name« < parentclass»
Ru ame
members
by members
end
end
Wi
ndo
ws
Po N/A
wer
She
ll
Sm
[10] [11]
allt
alk
Jav
aSc class name
ript
«extends parentclass» { members }
(ES
6)
trait TraitName
extends
class ConcreteClass(constructor
OtherTrait1
params)
with
extends ParentClass package
Sca OtherTrait2
la with Trait1 with Trait2 with Trait2 { name
with
// members
OtherTrait3 {
}
// members
}
CLASS-ID. name« INHERITS« FROM»
parentclasses». INTERFACE-
ID.name« INHER
FACTORY« IMPLEMENTS interfaces».
ITS« FROM»
class-members
CO interfaces».
END FACTORY.
BO members N/A
L OBJECT« IMPLEMENTS interfaces».
END
instance-members
INTERFACE name
END OBJECT.
.
END CLASS name.
namespac
interface name
class name «inherits parentclass» e name
Co «inheritsparen
«implements interfaces» T ab
bra tinterfaces»
T ab ↹ members ↹ membe
T ab ↹ members
rs
Class members[edit]
Constructors and destructors[edit]
methods
constructor «importing parameter
ABAP = argument»
Object N/A
method
s
constructor. instructions endmeth
od. [13]
~class()
C++ class(«parameters») «: initialize
{ instructions
(STL) rs [14] » { instructions }
}
void ~class()
class(«parameters»)
C# Dispose(){ ins { instruc
{ instructions }
tructions} tions}
~this()
this(«parameters»)
D { instruc
{ instructions }
tions }
~class()
eC class() { instructions } { instructions
}
void
finalize(
class(«parameters»)
Java )
{ instructions }
{instruct
ions }
[15] [16]
Eiffel
- (id)init
{ instructions... return self; -
-
Object } or
(void)dealloc (void)fin
ive-C - (id)initWithFoo:parameter
(Coco {instructions alize
a) «bar:parameter {instruct
}
...» { instructions... return ions }
self; }
deinit
init(«parameters»)
Swift { instructions
{ instructions }
}
def
__del__(s
Pytho def __init__(self«, parameters»): elf):
n T ab ↹ instructions T ab
↹ instru
ctions
Overrides
Visual Sub New(«parameters») Sub Dispose()
Sub
Basic instructions instructions
.NET Finalize(
End Sub End Sub
)
instructi
ons
End Sub
Sub
Sub Constructor(«parameters»)
Destructor()
Xojo instructions
instructions
End Sub
End Sub
function
function
__destruct()
PHP __construct(«parameters»)
{instructions
{ instructions }
}
sub new { my
sub DESTROY {
($class«, parameters») = @_; my
my ($self) =
Perl $self = {}; instructions
@_; instructio
... bless($self, $class); return
ns }
$self; }
submethod BUILD
{ instructions } or submethod
«multi » method DESTROY
Perl 6
new(««$self: »parameters») { {instructions
self.bless(*, field1 =>value1, }
...); ... instructions }
def initialize«(parameters)»
Ruby instructions N/A
end
Windo
ws N/A
Power
Shell
JavaSc constructor(«parameters»)
ript
{ instructions }
(ES6)
def dispose
cue init(parameters)
T ab
Cobra T ab ↹ base.init
↹ instruction
T ab ↹ instructions
s
(defmethod initialize-object
ISLIS
((instance <class-name>)
P
initvalues)
Fields[edit]
private protected
AB public
AP section. [21 ]
data section.[21 ] d
section.[21 ] data fie [22]
package
public type field private type type
D «= value»; field «=value»; field
«=value»
;
type
protected ty
field
Java pe field
«=value»
«=value»;
;
private type
eC public type field;
field;
feature feature
feature feature {NONE} {current_cla {FRIEND}
Eiffe
l field: TYPE field: TYPE ss}
field:
field: TYPE
TYPE
Obje @package
@private type @protected t
ctive @public type field; type
field; ype field;
-C field;
Swif N/A
t
Sma
[24]
lltal N/A N/A
k
protected
public $field private $field
PHP $field
«= value»; «= value»;
«= value»;
$self->{field}
Perl N/A
= value; [25]
Add-Member
«-
Win MemberType »NotePro
dow perty
s «-Name »Bar «- N/A
Pow
erSh Value »value
ell -
InputObject variabl
e
val «mutable
OCa »
N/A N/A
ml field = valu
e
let «mutable»
F# N/A N/A
field = value
CO level-number field
N/A N/A N/A
BOL clauses. [27]
(field :initform va
lue :accessor acces
ISLI sor-
SP
name :initarg keywo
rd)
Python
Visual
Basic
.NET
Xojo
Windo
ws [cls]::member
Power
Shell
N/
F# A
cls.member