comp.lang.ada
 help / color / mirror / Atom feed
* Help - Constructors - ASAP.
@ 1998-07-15  0:00 Maxim Senin
  1998-07-16  0:00 ` Stephen Leake
  0 siblings, 1 reply; 26+ messages in thread
From: Maxim Senin @ 1998-07-15  0:00 UTC (permalink / raw)


How to write constructor?

I tried to define constraints in type def, but if  have derived type, this will
not work:

type    A (param1, param2 : TypeOfParam) is new BaseType with record
        fld1 : TypeOfParam := param1;
        fld2 : TypeOfParam := param2;
    end record;

type    B (param : AnotherType) is new A with record    -- how can I set fld1
and fld2 using constraints?
        fld3 : AnotherType := param;
    end record;

Furthermore, if A and B are private types, then following code will also not
compile:

private
    type A.......;
    type B... is new A.....;

instanceOfA := new B' (fld1 => ..., fld2 => ..., fld3 => ...);
-- error: expected private type "B"
-- found a composite type

So, I think, constraints will not work. I see the following way to handle this:
types can defined public or setters must be provided. 1st approach is not good -
for example, if I want the object to be constucted once, and then be read-only.
For example, an event object is constucted once, and then clients can read data
from it:

    event := new Event (eventSource, eventType, eventData);
    ...
    if ((getSource (event) = this'Access) and (getType (event) = KEY_PRESSED))
then
        ...

Will anybody tell me the way to provide constuctors for objects in this manner?

I thought about defining functions:

function newEvent (eventSource : Object, eventType : EventTypes, eventData :
EventDataType) return Event is
ret    : Event;
begin
    ret := new Event;
    ret.source := eventSource;
    return  (eventSource, eventType, eventData);
end;

Hope to hear from you...

Maxim




^ permalink raw reply	[flat|nested] 26+ messages in thread
* Help - Constructors - ASAP.
@ 1998-07-23  0:00 Maxim Senin
  1998-07-26  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 26+ messages in thread
From: Maxim Senin @ 1998-07-23  0:00 UTC (permalink / raw)


How to write constructor?

I tried to define constraints in type def, but if  have derived type, this
will not work:

type    A (param1, param2 : TypeOfParam) is new BaseType with record
        fld1 : TypeOfParam := param1;
        fld2 : TypeOfParam := param2;
    end record;

type    B (param : AnotherType) is new A with record    -- how can I set
fld1 and fld2 using constraints?
        fld3 : AnotherType := param;
    end record;

Furthermore, if A and B are private types, then following code will also not
compile:

private
    type A.......;
    type B... is new A.....;

instanceOfA := new B' (fld1 => ..., fld2 => ..., fld3 => ...);
-- error: expected private type "B"
-- found a composite type

So, I think, constraints will not work. I see the following way to handle
this: types can defined public or setters
must be provided. 1st approach is not good - for example, if I want the
object to be constucted once, and then
be read-only. For example, an event object is constucted once, and then
clients can read data from it:

    event := new Event (eventSource, eventType, eventData);
    ...
    if ((getSource (event) = this'Access) and (getType (event) =
KEY_PRESSED)) then
        ...

Will anybody tell me the way to provide constuctors for objects in this
manner?

I thought about defining functions:

function newEvent (eventSource : Object, eventType : EventTypes, eventData :
EventDataType) return Event is
ret    : Event;
begin
    ret := new Event;
    ret.source := eventSource;
    return  (eventSource, eventType, eventData);
end;

Hope to hear from you...

Maxim









^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~1998-08-10  0:00 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-07-15  0:00 Help - Constructors - ASAP Maxim Senin
1998-07-16  0:00 ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
1998-07-23  0:00 Maxim Senin
1998-07-26  0:00 ` Matthew Heaney
1998-07-27  0:00   ` dennison
1998-07-30  0:00     ` Robert I. Eachus
1998-07-30  0:00       ` tedennison
1998-07-31  0:00         ` Mats Weber
1998-07-31  0:00           ` Robert I. Eachus
1998-08-01  0:00             ` Matthew Heaney
1998-07-31  0:00           ` dennison
1998-08-01  0:00             ` Matthew Heaney
1998-08-01  0:00             ` Robert Dewar
1998-08-01  0:00               ` Matthew Heaney
1998-08-03  0:00             ` Mats Weber
1998-07-31  0:00         ` Matthew Heaney
1998-08-01  0:00       ` Robert Dewar
1998-08-01  0:00         ` Matthew Heaney
1998-08-03  0:00           ` Mats Weber
1998-08-03  0:00             ` Matthew Heaney
1998-08-03  0:00               ` Mats Weber
1998-08-04  0:00                 ` Matthew Heaney
1998-08-04  0:00                   ` Mats Weber
1998-08-05  0:00                     ` Matthew Heaney
1998-08-10  0:00           ` Robert I. Eachus
1998-08-03  0:00         ` tedennison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox