Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
19
Task/Abstract-type/AmigaE/abstract-type.amiga
Normal file
19
Task/Abstract-type/AmigaE/abstract-type.amiga
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
OBJECT fruit
|
||||
ENDOBJECT
|
||||
|
||||
PROC color OF fruit IS EMPTY
|
||||
|
||||
OBJECT apple OF fruit
|
||||
ENDOBJECT
|
||||
|
||||
PROC color OF apple IS WriteF('red ')
|
||||
|
||||
OBJECT orange OF fruit
|
||||
ENDOBJECT
|
||||
|
||||
PROC color OF orange IS WriteF('orange ')
|
||||
|
||||
PROC main()
|
||||
DEF a:PTR TO apple,o:PTR TO orange,x:PTR TO fruit
|
||||
FORALL({x},[NEW a, NEW o],`x.color())
|
||||
ENDPROC
|
||||
61
Task/Abstract-type/Eiffel/abstract-type-2.e
Normal file
61
Task/Abstract-type/Eiffel/abstract-type-2.e
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
note
|
||||
title: "Prototype Person"
|
||||
description: "Abstract notion of a {PERSON}."
|
||||
synopsis: "[
|
||||
Abstract Data Types as represented by any Eiffel class, fully or partially implemented, are
|
||||
not just about the attribute and routine features of the class (deferred or implemented).
|
||||
The class and each feature may also have specification rules expressed as preconditions,
|
||||
post-conditions, and class invariants. Other assertion contracts may be applied to fully
|
||||
implemented features as well.
|
||||
|
||||
In the example below, while `age' is deferred (i.e. "abstract"), we have coded a rule which
|
||||
states that any caller of `age' must only do so after a `birth_date' has been defined and
|
||||
attached to that feature. Failing to do so will cause a contract violation. Moreover, the
|
||||
class invariant makes two strong assertions that must always hold for any implemented version
|
||||
of {PERSON}: The `birth_date' (if attached--that is--not Void or null) must be in the past
|
||||
and never in the future. Also, if "Years" are used to represent the age, the calculation of
|
||||
`age' must always agree with "current year - birth year = age".
|
||||
|
||||
This form of Abstract Data Type specification has very clear advantages in that not only
|
||||
must client code or descendents conform statically, implementing what is deferred, but they
|
||||
must also obey the rules of the assertions dynamically in a polymorphic run-time situation.
|
||||
]"
|
||||
|
||||
deferred class
|
||||
PERSON
|
||||
|
||||
feature -- Access
|
||||
|
||||
first_name,
|
||||
last_name,
|
||||
middle_name,
|
||||
suffix: STRING
|
||||
|
||||
birth_date: detachable DATE
|
||||
-- Date-of-Birth for Current {PERSON}.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Basic Operations
|
||||
|
||||
age: NATURAL_64
|
||||
-- Age of Current {PERSON} in some undefined units.
|
||||
require
|
||||
has_birth_date: attached birth_date
|
||||
deferred
|
||||
end
|
||||
|
||||
age_units: STRING
|
||||
-- Unit-of-Measure (UOM) of `age'.
|
||||
attribute
|
||||
Result := year_unit_string
|
||||
end
|
||||
|
||||
year_unit_string: STRING = "Years"
|
||||
|
||||
invariant
|
||||
not_future: attached birth_date as al_birth_date implies al_birth_date < (create {DATE}.make_now)
|
||||
accurate_age: attached birth_date as al_birth_date and then age > 0 and then age_units.same_string (year_unit_string)
|
||||
implies ((create {DATE}.make_now).year - al_birth_date.year) = age
|
||||
|
||||
end
|
||||
3
Task/Abstract-type/Forth/abstract-type-2.fth
Normal file
3
Task/Abstract-type/Forth/abstract-type-2.fth
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
include FMS-SI.f
|
||||
|
||||
The FMS object extension uses duck typing and so has no need for abstract types.
|
||||
16
Task/Abstract-type/Fortran/abstract-type.f
Normal file
16
Task/Abstract-type/Fortran/abstract-type.f
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
! abstract derived type
|
||||
type, abstract :: TFigure
|
||||
real(rdp) :: area
|
||||
contains
|
||||
! deferred method i.e. abstract method = must be overridden in extended type
|
||||
procedure(calculate_area), deferred, pass :: calculate_area
|
||||
end type TFigure
|
||||
! only declaration of the abstract method/procedure for TFigure type
|
||||
abstract interface
|
||||
function calculate_area(this)
|
||||
import TFigure !imports TFigure type from host scoping unit and makes it accessible here
|
||||
implicit none
|
||||
class(TFigure) :: this
|
||||
real(rdp) :: calculate_area
|
||||
end function calculate_area
|
||||
end interface
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref savelog symbols binary
|
||||
options replace format comments java crossref symbols binary
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
class RCAbstractType public final
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue