Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
66
Task/Classes/COBOL/classes.cobol
Normal file
66
Task/Classes/COBOL/classes.cobol
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
CLASS-ID. my-class INHERITS base.
|
||||
|
||||
*> The 'INHERITS base' and the following ENVIRONMENT DIVISION
|
||||
*> are optional (in Visual COBOL).
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
CLASS base.
|
||||
|
||||
*> There is no way (as far as I can tell) of creating a
|
||||
*> constructor. However, you could wrap it with another
|
||||
*> method to achieve the desired effect.
|
||||
*>...
|
||||
|
||||
OBJECT.
|
||||
*> Instance data
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 instance-variable PIC 9(8).
|
||||
|
||||
*> Properties can have getters and setters automatically
|
||||
*> generated.
|
||||
01 a-property PIC 9(8) PROPERTY.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
|
||||
METHOD-ID. some-method.
|
||||
PROCEDURE DIVISION.
|
||||
*> ...
|
||||
END METHOD some-method.
|
||||
END OBJECT.
|
||||
END CLASS my-class.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. example-class-use.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
*> These declarations brings the class and property into
|
||||
*> scope.
|
||||
CLASS my-class
|
||||
PROPERTY a-property.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
*> Declaring a my-class reference variable.
|
||||
01 instance USAGE OBJECT REFERENCE my-class.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
|
||||
*> Invoking a static method or (in this case) a constructor.
|
||||
INVOKE my-class "new" RETURNING instance
|
||||
|
||||
*> Invoking an instance method.
|
||||
INVOKE instance "some-method"
|
||||
|
||||
*> Using the setter and getter of a-property.
|
||||
MOVE 5 TO a-property OF instance
|
||||
DISPLAY a-property OF instance
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
||||
END PROGRAM example-class-use.
|
||||
46
Task/Classes/Component-Pascal/classes.component
Normal file
46
Task/Classes/Component-Pascal/classes.component
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
MODULE Graphics;
|
||||
IMPORT StdLog;
|
||||
TYPE
|
||||
(* class *)
|
||||
Point* = POINTER TO LIMITED RECORD
|
||||
x-,y-: INTEGER; (* Instance variables *)
|
||||
END;
|
||||
|
||||
(* method *)
|
||||
PROCEDURE (p: Point) Abs*(): INTEGER,NEW;
|
||||
BEGIN
|
||||
RETURN p.x
|
||||
END Abs;
|
||||
|
||||
(* method *)
|
||||
PROCEDURE (p: Point) Ord*(): INTEGER,NEW;
|
||||
BEGIN
|
||||
RETURN p.y
|
||||
END Ord;
|
||||
|
||||
(* method *)
|
||||
PROCEDURE (p: Point) Show*,NEW;
|
||||
BEGIN
|
||||
StdLog.String("Point(");StdLog.Int(p.x);StdLog.String(",");
|
||||
StdLog.Int(p.y);StdLog.String(");");StdLog.Ln
|
||||
END Show;
|
||||
|
||||
(* constructor *)
|
||||
PROCEDURE NewPoint*(x,y: INTEGER): Point;
|
||||
VAR
|
||||
p: Point;
|
||||
BEGIN
|
||||
NEW(p);p.x := x;p.y := y;
|
||||
RETURN p
|
||||
END NewPoint;
|
||||
|
||||
PROCEDURE TestPoint*;
|
||||
VAR
|
||||
p: Point;
|
||||
BEGIN
|
||||
p := NewPoint(10,20);
|
||||
p.Show();
|
||||
StdLog.String("Abs:> ");StdLog.Int(p.Abs());StdLog.Ln;
|
||||
StdLog.String("Ord:> ");StdLog.Int(p.Ord());StdLog.Ln
|
||||
END TestPoint;
|
||||
END Graphics.
|
||||
19
Task/Classes/Nemerle/classes.nemerle
Normal file
19
Task/Classes/Nemerle/classes.nemerle
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
public class MyClass
|
||||
{
|
||||
public this() { } // the constructor in Nemerle is always named 'this'
|
||||
|
||||
public MyVariable : int
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public MyMethod() : void
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def myInstance = MyClass(); // no 'new' keyword needed
|
||||
myInstance.MyVariable = 42; // set MyVariable
|
||||
System.Console.WriteLine($"My variable is $(myInstance.MyVariable)") // get MyVariable
|
||||
23
Task/Classes/Vala/classes.vala
Normal file
23
Task/Classes/Vala/classes.vala
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
public class MyClass : Object {
|
||||
// Instance variable
|
||||
public int variable;
|
||||
|
||||
// Method
|
||||
public void some_method() {
|
||||
variable = 24;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
public MyClass() {
|
||||
variable = 42;
|
||||
}
|
||||
}
|
||||
void main() {
|
||||
// Class instance
|
||||
MyClass instance = new MyClass();
|
||||
print("%d\n", instance.variable);
|
||||
instance.some_method();
|
||||
print("%d\n", instance.variable);
|
||||
instance.variable = 84;
|
||||
print("%d\n", instance.variable);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue