"The class is an Object. Just send a message to a class, usually #new or #new:, and many others, for example:" Pointy x: 10 y: 20. Array with: -1 with: 3 with: 2.
class name definition «inheriting from parentclass». «interfaces: interfaces.» method_and_field_declarations endclass. class name implementation. method_implementations endclass.
interface name. members endinterface.
N/A
C++ (STL)
class name« : public parentclasses[5]» { members };
namespace name { members }
C#
class name« : «parentclass»«, interfaces»» { members }
interface name« : parentinterfaces» { members }
D
module name; members
Java
class name« extends parentclass»« implements interfaces» { members }
interface name« extends parentinterfaces» { members }
package name; «@ISA = qw(parentclasses[5]);» members 1;
package name; members
Perl 6
class name «is parentclass «is parentclass ...[5]»» «does role «does role ...»» { members }
role name «does role «does role ...»» { members }
module name { members }
Ruby
class name« < parentclass» members end
module name members end
Windows PowerShell
N/A
OCaml
class name «parameters» = object «(self)» «inherit parentclass «parameters» «inherit parentclass «parameters» ...[5]»» 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
"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"
this.method = function(«parameters») {instructions} name«.prototype.method = function(«parameters») {instructions} Just assign a function to it in a method
this.method = function(«parameters») {instructions... return value;} name«.prototype.method = function(«parameters») {instructions... return value;} Just assign a function to it in a method
Properties
How to declare a property named "Bar"
Manually implemented
read-write
read-only
write-only
ABAP Objects
N/A
C++ (STL)
N/A
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;}
Java
N/A
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 }
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)
def getBar(self): Tab ↹ instructions Tab ↹return value bar = property(getBar)
type operatorsymbol(type operand2) { instructions }
type operator()(«parameters») { instructions }
C#
static type operator symbol(type operand) { instructions }
static type operator symbol(type operand1, type operand2) { instructions }
N/A
D
type opUnary(string s)() if (s == "symbol") { instructions }
type opBinary(string s)(type operand2) if (s == "symbol") { instructions } type opBinaryRight(string s)(type operand1) if (s == "symbol") { switch (s) { instructions }
^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.
^In Python interfaces are classes whose methods have pass as their bodies
^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(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.
^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
^ abcScope 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, you don't declare specific fields or methods to be accessible by outside things. Rather, you declare outside classes to be friends to have access to the class's fields or methods.
^In C++, you don't declare specific fields to be accessible by outside things. Rather, you declare outside functions and classes to be friends to have access to the class's fields. See friend function and friend class for more details.
^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
^The declaration and implementation of methods in C++ are usually separate. Methods are declared inside the class definition (which is usually included in a header file) using the syntax
type foo(«parameters»);
The implementation of methods is usually provided in a separate source file, with the following syntax
type class::foo(«parameters») { instructions }
Although the body of a method could be included with the declaration inside the class definition, as shown in the table here, this is generally a bad idea. Because the class definition will need to be included with every source file which uses the fields or methods of the class, having code in the class definition will cause the method code to be compiled with every source file, increasing the size of the code. There are some circumstances, however, where 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 you have a very short one-liner method, it may make it faster to allow the compiler to inline it, by including the body along with the declaration. Also, if you have a template class or method, then all the code must be included with the declaration, because only with the code can the template be instantiated.
parameter = argument 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 desired. Instead, you can use the BaseClassName::member syntax 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 not supported in other compilers.[1]
^ abcdefThe keyword here is not a value in itself and it can only be used to access a method of the superclass.
^ abIn 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 "inherit parent_class «parameters» as super". Here "super" is the name we gave to the variable associated with this parent object. It can be named something else.
^However, if you really wanted the ability to have an "optional" value in OCaml, you would wrap the value inside an option type, whose 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 a pointer). Can be customized by overloading the object's == operator
^Only accessible from within the class itself, since the clone() method inherited from Object is protected, unless the class overrides the method and makes it public. If you use the clone() inherited from Object, your class will need to implement the Cloneable interface to allow cloning.