Overriding et primitives.
Pascal <[email protected]>
| Newsgroups | gmane.comp.lang.ada.france |
|---|---|
| Message-ID | <[email protected]> |
Bonjour.
Deux questions sur les primitives de type objet ("tagged") avec Ada
2005.
1) Ada 2005 a ajouté le mot clé "overriding", voir RM Ada 2005 :
"8.3.1 Overriding Indicators
1/2
An overriding_indicator is used to declare that an operation is
intended to override (or not override) an inherited operation.
Syntax
2/2
overriding_indicator ::= [not] overriding"
Sans ajouter de mot clé supplémentaire, cette fonctionnalité aurait
pu s'obtenir avec un ou deux pragma comme:
pragma Overriding (Identifier);
pragma Not_Overriding (Identifier);
Qu'en pensez-vous ?
2) Ada 2005 permet de ne plus exiger de redefinition d'une fonction
retournant le type objet, voir "Rationale for Ada 2005" :
"The reader may recall the general rule in Ada 95 that a function
that is a primitive operation of a
tagged type and returns a value of the type, must always be
overridden when the type is extended.
Ada 2005 sensibly allows the functions to be inherited provided
that the extension is visibly null (and that there is no new
discriminant part) and so no overriding is
required."
Cependant dans le cas d'une extension non nulle du type objet,
certaines situations font que la redéfinition de la fonction telle
quelle (avec les mêmes paramètres) est inutile pour l'utilisateur
mais que sa surcharge avec d'autres paramètres est utile.
Ne serait-il pas intéressant dans ce cas d'utiliser un pragma comme :
pragma Not_A_Primitive (Identifier);
Exemple (trivial ;-) :
package ess_nap is
type Point is tagged record
X, Y : Integer;
end record;
function Init (X, Y : Integer) return Point;
pragma Not_A_Primitive (Init);
type Cercle is new Point with record
R : Integer;
end record;
-- function Init (X, Y : Integer) return Cercle; -- n'est pas utile !?
function Init (X, Y, R : Integer) return Cercle; -- celle-ci oui !
end ess_nap;
Qu'en pensez vous ?
Merci pour vos réponses, Pascal Pignard.
http://blady.pagesperso-orange.fr
_______________________________________________
Site WWW de l'association Ada-France: http://www.ada-france.org/
[email protected]
http://www.ada-france.org/mailman/listinfo/ada-france