From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,555956c1cdd22308 X-Google-Attributes: gid103376,public From: "Maxim Senin" Subject: Help - Constructors - ASAP. Date: 1998/07/23 Message-ID: <6p75qi$rcj@news.latnet.lv>#1/1 X-Deja-AN: 374142001 Organization: LatNet news site X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Newsgroups: comp.lang.ada Date: 1998-07-23T00:00:00+00:00 List-Id: 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