Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
58
Task/Abstract-type/COBOL/abstract-type.cobol
Normal file
58
Task/Abstract-type/COBOL/abstract-type.cobol
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
INTERFACE-ID. Shape.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
|
||||
METHOD-ID. perimeter.
|
||||
DATA DIVISION.
|
||||
LINKAGE SECTION.
|
||||
01 ret USAGE FLOAT-LONG.
|
||||
PROCEDURE DIVISION RETURNING ret.
|
||||
END METHOD perimeter.
|
||||
|
||||
METHOD-ID. shape-area.
|
||||
DATA DIVISION.
|
||||
LINKAGE SECTION.
|
||||
01 ret USAGE FLOAT-LONG.
|
||||
PROCEDURE DIVISION RETURNING ret.
|
||||
END METHOD shape-area.
|
||||
|
||||
END INTERFACE Shape.
|
||||
|
||||
|
||||
CLASS-ID. Rectangle.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
INTERFACE Shape.
|
||||
|
||||
OBJECT IMPLEMENTS Shape.
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 width USAGE FLOAT-LONG PROPERTY.
|
||||
01 height USAGE FLOAT-LONG PROPERTY.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
|
||||
METHOD-ID. perimeter.
|
||||
DATA DIVISION.
|
||||
LINKAGE SECTION.
|
||||
01 ret USAGE FLOAT-LONG.
|
||||
PROCEDURE DIVISION RETURNING ret.
|
||||
COMPUTE ret = width * 2.0 + height * 2.0
|
||||
GOBACK
|
||||
.
|
||||
END METHOD perimeter.
|
||||
|
||||
METHOD-ID. shape-area.
|
||||
DATA DIVISION.
|
||||
LINKAGE SECTION.
|
||||
01 ret USAGE FLOAT-LONG.
|
||||
PROCEDURE DIVISION RETURNING ret.
|
||||
COMPUTE ret = width * height
|
||||
GOBACK
|
||||
.
|
||||
END METHOD shape-area.
|
||||
END OBJECT.
|
||||
|
||||
END CLASS Rectangle.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
(* Abstract type *)
|
||||
Object = POINTER TO ABSTRACT RECORD END;
|
||||
|
||||
(* Integer inherits Object *)
|
||||
Integer = POINTER TO RECORD (Object)
|
||||
i: INTEGER
|
||||
END;
|
||||
(* Point inherits Object *)
|
||||
Point = POINTER TO RECORD (Object)
|
||||
x,y: REAL
|
||||
END;
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
(* Abstract method of Object *)
|
||||
PROCEDURE (dn: Object) Show*, NEW, ABSTRACT;
|
||||
|
||||
(* Implementation of the abstract method Show() in class Integer *)
|
||||
PROCEDURE (i: Integer) Show*;
|
||||
BEGIN
|
||||
StdLog.String("Integer(");StdLog.Int(i.i);StdLog.String(");");StdLog.Ln
|
||||
END Show;
|
||||
|
||||
(* Implementation of the abstract method Show() in class Point *)
|
||||
PROCEDURE (p: Point) Show*;
|
||||
BEGIN
|
||||
StdLog.String("Point(");StdLog.Real(p.x);StdLog.Char(',');
|
||||
StdLog.Real(p.y);StdLog.String(");");StdLog.Ln
|
||||
END Show;
|
||||
38
Task/Abstract-type/Nemerle/abstract-type.nemerle
Normal file
38
Task/Abstract-type/Nemerle/abstract-type.nemerle
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System.Console;
|
||||
|
||||
namespace RosettaCode
|
||||
{
|
||||
abstract class Fruit
|
||||
{
|
||||
abstract public Eat() : void;
|
||||
abstract public Peel() : void;
|
||||
|
||||
virtual public Cut() : void // an abstract class con contain a mixture of abstract and implemented methods
|
||||
{ // the virtual keyword allows the method to be overridden by derivative classes
|
||||
WriteLine("Being cut.");
|
||||
}
|
||||
}
|
||||
|
||||
interface IJuiceable
|
||||
{
|
||||
Juice() : void; // interfaces contain only the signatures of methods
|
||||
}
|
||||
|
||||
class Orange : Fruit, IJuiceable
|
||||
{
|
||||
public override Eat() : void // implementations of abstract methods need to be marked override
|
||||
{
|
||||
WriteLine("Being eaten.");
|
||||
}
|
||||
|
||||
public override Peel() : void
|
||||
{
|
||||
WriteLine("Being peeled.");
|
||||
}
|
||||
|
||||
public Juice() : void
|
||||
{
|
||||
WriteLine("Being juiced.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue