> For the special case where objects don't have 'invalid' states, but
> come fully into existence and stay, in a stack-like way, until they
> die, and where Ada 95's discriminant limitations don't cause
> difficulties, it would, IMHO, be desirable to use constructors rather
> than Create functions.
>    X:Object_Type(params);
> is simpler than
>    X:Object_Type := Create(params);
> and does not even have the possibility of forgetting the initial
> value assignment, or doing an erroneous later assignment.

Using discriminants to serve the role as parameters to constructors
seems to be inappropriate, unless their values are seen as relevant
throughout the life of the object.  If they are only affecting the
initial value of the object, it would seem to be better to use a parameterized
function as initial expression.

If you want to prevent the possibility of forgetting initial
value assignment, you could specify unknown discriminants
in the private type declaration.  E.g.:

    type Object_Type(<>) is private;

The full type need not have any discriminants at all, but by
doing the private declaration this way, a user of the type outside
the package is required to initialize all object declarations,
because simply "X : Object_Type;" is illegal (Object_Type is an
"indefinite" (view of a) type).

-Tucker Taft  [log in to unmask]