From: Maxim Senin <maks@tech.swh.lv>
Subject: Help - Constructors - ASAP.
Date: 1998/07/15
Date: 1998-07-15T00:00:00+00:00 [thread overview]
Message-ID: <35ACBAD6.CC060CEF@tech.swh.lv> (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
next reply other threads:[~1998-07-15 0:00 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-07-15 0:00 Maxim Senin [this message]
1998-07-16 0:00 ` Help - Constructors - ASAP 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 ` 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 ` Robert I. Eachus
1998-08-01 0:00 ` Matthew Heaney
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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox