Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'''Abstract type''' is a type without instances or without definition.
|
||||
|
||||
For example in [[object-oriented programming]] using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract types without any implementation are called '''interfaces'''. In the languages that do not support multiple [[inheritance]] ([[Ada]], [[Java]]), classes can, nonetheless, inherit from multiple interfaces. The languages with multiple inheritance (like [[C++]]) usually make no distinction between partially implementable abstract types and interfaces. Because the abstract type's implementation is incomplete, [[object-oriented programming | OO]] languages normally prevent instantiation from them (instantiation must derived from one of their descendant classes).
|
||||
For example in [[object-oriented programming]] using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract types without any implementation are called [[wp:Interface_(object-oriented_programming)|'''interfaces''']]. In the languages that do not support multiple [[inheritance]] ([[Ada]], [[Java]]), classes can, nonetheless, inherit from multiple interfaces. The languages with multiple inheritance (like [[C++]]) usually make no distinction between partially implementable abstract types and interfaces. Because the abstract type's implementation is incomplete, [[object-oriented programming | OO]] languages normally prevent instantiation from them (instantiation must derived from one of their descendant classes).
|
||||
|
||||
The term '''abstract datatype''' also may denote a type, with an implementation provided by the programmer rather than directly by the language (a '''built-in''' or an inferred type). Here the word ''abstract'' means that the implementation is abstracted away, irrelevant for the user of the type. Such implementation can and should be hidden if the language supports separation of implementation and specification. This hides complexity while allowing the implementation to change without repercussions on the usage. The corresponding software design practice is said to follow the [[wp:Information_hiding|information hiding principle]].
|
||||
|
||||
|
|
|
|||
3
Task/Abstract-type/Ada/abstract-type-1.adb
Normal file
3
Task/Abstract-type/Ada/abstract-type-1.adb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
type Queue is limited interface;
|
||||
procedure Enqueue (Lounge : in out Queue; Item : in out Element) is abstract;
|
||||
procedure Dequeue (Lounge : in out Queue; Item : in out Element) is abstract;
|
||||
2
Task/Abstract-type/Ada/abstract-type-2.adb
Normal file
2
Task/Abstract-type/Ada/abstract-type-2.adb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
type Scheduler is task interface;
|
||||
procedure Plan (Manager : in out Scheduler; Activity : in out Job) is abstract;
|
||||
10
Task/Abstract-type/Ada/abstract-type-3.adb
Normal file
10
Task/Abstract-type/Ada/abstract-type-3.adb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
with Ada.Finalization;
|
||||
...
|
||||
type Node is abstract new Ada.Finalization.Limited_Controlled and Queue with record
|
||||
Previous : not null access Node'Class := Node'Unchecked_Access;
|
||||
Next : not null access Node'Class := Node'Unchecked_Access;
|
||||
end record;
|
||||
overriding procedure Finalize (X : in out Node); -- Removes the node from its list if any
|
||||
overriding procedure Dequeue (Lounge : in out Node; Item : in out Element);
|
||||
overriding procedure Enqueue (Lounge : in out Node; Item : in out Element);
|
||||
procedure Process (X : in out Node) is abstract; -- To be implemented
|
||||
68
Task/Abstract-type/COBOL/abstract-type.cob
Normal file
68
Task/Abstract-type/COBOL/abstract-type.cob
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
INTERFACE-ID. Shape.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
METHOD-ID. perimeter.
|
||||
DATA DIVISION.
|
||||
LINKAGE SECTION.
|
||||
01 ret USAGE FLOAT-LONG.
|
||||
PROCEDURE DIVISION RETURNING ret.
|
||||
END METHOD perimeter.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
METHOD-ID. shape-area.
|
||||
DATA DIVISION.
|
||||
LINKAGE SECTION.
|
||||
01 ret USAGE FLOAT-LONG.
|
||||
PROCEDURE DIVISION RETURNING ret.
|
||||
END METHOD shape-area.
|
||||
|
||||
END INTERFACE Shape.
|
||||
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
CLASS-ID. Rectangle.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
INTERFACE Shape.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
OBJECT IMPLEMENTS Shape.
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 width USAGE FLOAT-LONG PROPERTY.
|
||||
01 height USAGE FLOAT-LONG PROPERTY.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
|
||||
IDENTIFICATION 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
|
||||
END-COMPUTE
|
||||
GOBACK.
|
||||
END METHOD perimeter.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
METHOD-ID. shape-area.
|
||||
DATA DIVISION.
|
||||
LINKAGE SECTION.
|
||||
01 ret USAGE FLOAT-LONG.
|
||||
PROCEDURE DIVISION RETURNING ret.
|
||||
COMPUTE
|
||||
ret = width * height
|
||||
END-COMPUTE
|
||||
GOBACK.
|
||||
END METHOD shape-area.
|
||||
|
||||
END OBJECT.
|
||||
|
||||
END CLASS Rectangle.
|
||||
24
Task/Abstract-type/Gleam/abstract-type.gleam
Normal file
24
Task/Abstract-type/Gleam/abstract-type.gleam
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
pub fn main() {
|
||||
let positive = new(1)
|
||||
let zero = new(0)
|
||||
let negative = new(-1)
|
||||
|
||||
echo to_int(positive)
|
||||
echo to_int(zero)
|
||||
echo to_int(negative)
|
||||
}
|
||||
|
||||
pub opaque type PositiveInt {
|
||||
PositiveInt(inner: Int)
|
||||
}
|
||||
|
||||
pub fn new(i: Int) -> PositiveInt {
|
||||
case i >= 0 {
|
||||
True -> PositiveInt(i)
|
||||
False -> PositiveInt(0)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_int(i: PositiveInt) -> Int {
|
||||
i.inner
|
||||
}
|
||||
44
Task/Abstract-type/Haxe/abstract-type-1.hx
Normal file
44
Task/Abstract-type/Haxe/abstract-type-1.hx
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
interface Vocal {
|
||||
public function speak():String;
|
||||
}
|
||||
|
||||
interface Gravitational {
|
||||
public function getWeight():Int;
|
||||
}
|
||||
|
||||
abstract class Dog implements Vocal implements Gravitational {
|
||||
public function speak():String {
|
||||
return "Woof";
|
||||
}
|
||||
|
||||
public function new() {}
|
||||
}
|
||||
|
||||
class Chihuahua extends Dog {
|
||||
public function getWeight():Int {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
class GreatDane extends Dog {
|
||||
public function getWeight():Int {
|
||||
return 150;
|
||||
}
|
||||
}
|
||||
|
||||
class Main {
|
||||
static public function main():Void {
|
||||
var dogs:Array<Dog> = [];
|
||||
|
||||
var david = new Chihuahua();
|
||||
var goliath = new GreatDane();
|
||||
|
||||
dogs.push(david);
|
||||
dogs.push(goliath);
|
||||
|
||||
for (dog in dogs) {
|
||||
trace(dog.speak());
|
||||
trace(dog.getWeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Task/Abstract-type/Haxe/abstract-type-2.hx
Normal file
3
Task/Abstract-type/Haxe/abstract-type-2.hx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class abstraction()
|
||||
abstract method compare(l,r) # generates runerr(700, "method compare()")
|
||||
end
|
||||
92
Task/Abstract-type/PowerShell/abstract-type-1.ps1
Normal file
92
Task/Abstract-type/PowerShell/abstract-type-1.ps1
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#Requires -Version 5.0
|
||||
|
||||
Class Player
|
||||
{
|
||||
<#
|
||||
Properties: Name, Team, Position and Number
|
||||
#>
|
||||
[string]$Name
|
||||
|
||||
[ValidateSet("Baltimore Ravens","Cincinnati Bengals","Cleveland Browns","Pittsburgh Steelers",
|
||||
"Chicago Bears","Detroit Lions","Green Bay Packers","Minnesota Vikings",
|
||||
"Houston Texans","Indianapolis Colts","Jacksonville Jaguars","Tennessee Titans",
|
||||
"Atlanta Falcons","Carolina Panthers","New Orleans Saints","Tampa Bay Buccaneers",
|
||||
"Buffalo Bills","Miami Dolphins","New England Patriots","New York Jets",
|
||||
"Dallas Cowboys","New York Giants","Philadelphia Eagles","Washington Redskins",
|
||||
"Denver Broncos","Kansas City Chiefs","Oakland Raiders","San Diego Chargers",
|
||||
"Arizona Cardinals","Los Angeles Rams","San Francisco 49ers","Seattle Seahawks")]
|
||||
[string]$Team
|
||||
|
||||
[ValidateSet("C","G","T","QB","RB","WR","TE","DT","DE","ILB","OLB","CB","S","K","H","LS","P","KOS","R")]
|
||||
[string]$Position
|
||||
|
||||
[ValidateRange(0,99)]
|
||||
[int]$Number
|
||||
|
||||
<#
|
||||
Constructor: Creates a new Player object, with the specified Name, Team, Position and Number.
|
||||
#>
|
||||
Player([string]$Name, [string]$Team, [string]$Position, [int]$Number)
|
||||
{
|
||||
$this.Name = (Get-Culture).TextInfo.ToTitleCase("$Name")
|
||||
$this.Team = (Get-Culture).TextInfo.ToTitleCase("$Team")
|
||||
$this.Position = $Position.ToUpper()
|
||||
$this.Number = $Number
|
||||
}
|
||||
|
||||
<#
|
||||
Methods: Trade the player to a different team (optional parameters for methods in PowerShell 5 classes are not available. Boo!!)
|
||||
An overloaded method is a method with the same name as another method but in a different context,
|
||||
in this case with different parameters.
|
||||
#>
|
||||
Trade([string]$NewTeam)
|
||||
{
|
||||
[string[]]$league = "Baltimore Ravens","Cincinnati Bengals","Cleveland Browns","Pittsburgh Steelers",
|
||||
"Chicago Bears","Detroit Lions","Green Bay Packers","Minnesota Vikings",
|
||||
"Houston Texans","Indianapolis Colts","Jacksonville Jaguars","Tennessee Titans",
|
||||
"Atlanta Falcons","Carolina Panthers","New Orleans Saints","Tampa Bay Buccaneers",
|
||||
"Buffalo Bills","Miami Dolphins","New England Patriots","New York Jets",
|
||||
"Dallas Cowboys","New York Giants","Philadelphia Eagles","Washington Redskins",
|
||||
"Denver Broncos","Kansas City Chiefs","Oakland Raiders","San Diego Chargers",
|
||||
"Arizona Cardinals","Los Angeles Rams","San Francisco 49ers","Seattle Seahawks"
|
||||
|
||||
if ($NewTeam -in $league | Where-Object {$_ -notmatch $this.Team})
|
||||
{
|
||||
$this.Team = (Get-Culture).TextInfo.ToTitleCase("$NewTeam")
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid Team"
|
||||
}
|
||||
}
|
||||
|
||||
Trade([string]$NewTeam, [int]$NewNumber)
|
||||
{
|
||||
[string[]]$league = "Baltimore Ravens","Cincinnati Bengals","Cleveland Browns","Pittsburgh Steelers",
|
||||
"Chicago Bears","Detroit Lions","Green Bay Packers","Minnesota Vikings",
|
||||
"Houston Texans","Indianapolis Colts","Jacksonville Jaguars","Tennessee Titans",
|
||||
"Atlanta Falcons","Carolina Panthers","New Orleans Saints","Tampa Bay Buccaneers",
|
||||
"Buffalo Bills","Miami Dolphins","New England Patriots","New York Jets",
|
||||
"Dallas Cowboys","New York Giants","Philadelphia Eagles","Washington Redskins",
|
||||
"Denver Broncos","Kansas City Chiefs","Oakland Raiders","San Diego Chargers",
|
||||
"Arizona Cardinals","Los Angeles Rams","San Francisco 49ers","Seattle Seahawks"
|
||||
|
||||
if ($NewTeam -in $league | Where-Object {$_ -notmatch $this.Team})
|
||||
{
|
||||
$this.Team = (Get-Culture).TextInfo.ToTitleCase("$NewTeam")
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid Team"
|
||||
}
|
||||
|
||||
if ($NewNumber -in 0..99)
|
||||
{
|
||||
$this.Number = $NewNumber
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid Number"
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Task/Abstract-type/PowerShell/abstract-type-2.ps1
Normal file
2
Task/Abstract-type/PowerShell/abstract-type-2.ps1
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$player1 = [Player]::new("sam bradford", "philadelphia eagles", "qb", 7)
|
||||
$player1
|
||||
2
Task/Abstract-type/PowerShell/abstract-type-3.ps1
Normal file
2
Task/Abstract-type/PowerShell/abstract-type-3.ps1
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$player1.Trade("minnesota vikings", 8)
|
||||
$player1
|
||||
2
Task/Abstract-type/PowerShell/abstract-type-4.ps1
Normal file
2
Task/Abstract-type/PowerShell/abstract-type-4.ps1
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$player2 = [Player]::new("demarco murray", "philadelphia eagles", "rb", 29)
|
||||
$player2
|
||||
2
Task/Abstract-type/PowerShell/abstract-type-5.ps1
Normal file
2
Task/Abstract-type/PowerShell/abstract-type-5.ps1
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$player2.Trade("tennessee titans")
|
||||
$player2
|
||||
|
|
@ -1,13 +1,33 @@
|
|||
class BaseQueue(object):
|
||||
"""Abstract/Virtual Class
|
||||
"""
|
||||
def __init__(self):
|
||||
self.contents = list()
|
||||
raise NotImplementedError
|
||||
def Enqueue(self, item):
|
||||
raise NotImplementedError
|
||||
def Dequeue(self):
|
||||
raise NotImplementedError
|
||||
def Print_Contents(self):
|
||||
for i in self.contents:
|
||||
print i,
|
||||
from abc import ABC
|
||||
from abc import abstractmethod
|
||||
from typing import Literal
|
||||
|
||||
class Pet(ABC):
|
||||
def __init__(self, name: str) -> None:
|
||||
self.name = name
|
||||
|
||||
@abstractmethod
|
||||
def speak(self) -> str: ...
|
||||
|
||||
class Cat(Pet):
|
||||
def speak(self) -> str:
|
||||
return f"{self.name} says meow"
|
||||
|
||||
class Dog(Pet):
|
||||
def __init__(self, name: str, size: Literal["small", "big"] = "small") -> None:
|
||||
super().__init__(name)
|
||||
self.size = size
|
||||
|
||||
def speak(self) -> str:
|
||||
return "woof" if self.size == "small" else "loud woof"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pets: list[Pet] = [
|
||||
Cat(name="Fluffy"),
|
||||
Dog(name="Gary"),
|
||||
Dog(name="Sue", size="big"),
|
||||
]
|
||||
|
||||
for pet in pets:
|
||||
print(pet.speak())
|
||||
|
|
|
|||
|
|
@ -1,21 +1,31 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
from typing import Literal
|
||||
from typing import Protocol
|
||||
|
||||
class BaseQueue():
|
||||
"""Abstract Class
|
||||
"""
|
||||
__metaclass__ = ABCMeta
|
||||
class Pet(Protocol):
|
||||
def speak(self) -> str: ...
|
||||
|
||||
def __init__(self):
|
||||
self.contents = list()
|
||||
class Cat:
|
||||
def __init__(self, name: str) -> None:
|
||||
self.name = name
|
||||
|
||||
@abstractmethod
|
||||
def Enqueue(self, item):
|
||||
pass
|
||||
def speak(self) -> str:
|
||||
return f"{self.name} says meow"
|
||||
|
||||
@abstractmethod
|
||||
def Dequeue(self):
|
||||
pass
|
||||
class Dog:
|
||||
def __init__(self, name: str, size: Literal["small", "big"] = "small") -> None:
|
||||
self.name = name
|
||||
self.size = size
|
||||
|
||||
def Print_Contents(self):
|
||||
for i in self.contents:
|
||||
print i,
|
||||
def speak(self) -> str:
|
||||
return "woof" if self.size == "small" else "loud woof"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pets: list[Pet] = [
|
||||
Cat(name="Fluffy"),
|
||||
Dog(name="Gary"),
|
||||
Dog(name="Sue", size="big"),
|
||||
]
|
||||
|
||||
for pet in pets:
|
||||
print(pet.speak())
|
||||
|
|
|
|||
1
Task/Abstract-type/ReScript/abstract-type.res
Normal file
1
Task/Abstract-type/ReScript/abstract-type.res
Normal file
|
|
@ -0,0 +1 @@
|
|||
type t
|
||||
44
Task/Abstract-type/Rebol/abstract-type.rebol
Normal file
44
Task/Abstract-type/Rebol/abstract-type.rebol
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
REBOL [
|
||||
Title: "Abstract Type"
|
||||
URL: http://rosettacode.org/wiki/Abstract_type
|
||||
]
|
||||
|
||||
; The "shape" class is an abstract class -- it defines the "pen"
|
||||
; property and "line" method, but "size" and "draw" are undefined and
|
||||
; unimplemented.
|
||||
|
||||
shape: make object! [
|
||||
pen: "X"
|
||||
size: none
|
||||
|
||||
line: func [count][loop count [prin self/pen] prin crlf]
|
||||
draw: does [none]
|
||||
]
|
||||
|
||||
; The "box" class inherits from "shape" and provides the missing
|
||||
; information for drawing boxes.
|
||||
|
||||
box: make shape [
|
||||
size: 10
|
||||
draw: does [loop self/size [line self/size]]
|
||||
]
|
||||
|
||||
; "rectangle" also inherits from "shape", but handles the
|
||||
; implementation very differently.
|
||||
|
||||
rectangle: make shape [
|
||||
size: 20x10
|
||||
draw: does [loop self/size/y [line self/size/x]]
|
||||
]
|
||||
|
||||
; Unlike some languages discussed, REBOL has absolutely no qualms
|
||||
; about instantiating an "abstract" class -- that's how I created the
|
||||
; derived classes of "rectangle" and "box", after all.
|
||||
|
||||
s: make shape [] s/draw ; Nothing happens.
|
||||
|
||||
print "A box:"
|
||||
b: make box [pen: "O" size: 5] b/draw
|
||||
|
||||
print "^/A rectangle:"
|
||||
r: make rectangle [size: 32x5] r/draw
|
||||
Loading…
Add table
Add a link
Reference in a new issue