comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Constructors with multiple inheritance
Date: Fri, 30 Sep 2011 18:42:39 +0200
Date: 2011-09-30T18:42:39+02:00	[thread overview]
Message-ID: <1gnrks1djlaok.1k0r5f8z9ylfx.dlg@40tude.net> (raw)
In-Reply-To: 23774546.1654.1317391464047.JavaMail.geo-discussion-forums@yqnk41

On Fri, 30 Sep 2011 07:04:24 -0700 (PDT), in comp.lang.ada you wrote:

>>> Yes, I agree. But that's the point. I want to reserve the address (so I
>>> can build my queues from there).
>> 
>> The problem is not the result, but the argument of Construct.
> 
> Ok. But did not understand the problem if the argument is null.

Because null cannot be dereferenced. If you want null allowed you have to
declare it as:

   function Construct (Object_Reference : access Parent_Class)
      return Parent_Class_Ptr;

or

   function Construct (Object_Reference : Parent_Class_Ptr)
      return Parent_Class_Ptr;

The first variant is a "method" of Parent_Class in the first argument. The
second variant is not.

> So if I inherit a class

Technically you cannot inherit class. Class is a set of types closed upon
derivation. When you derive type S from type T, then S and T are members of
the class rooted in the type T. S inherits operations etc from T.

What in C++ is called class is in Ada a tagged type and/or a class-wide
type, because C++ fails to distinguish them.

> which have a method defined in the "function Construct return
> Parent_Class_Ptr"

Construct is not a "method" of Parent_Class because there is no covariant
argument/result of that type.

> form instead of the "function Construct (Obj :
>  Parent_Class) return Parent_Class_Ptr"

This one is a "method" (primitive operation in Ada terms) in the argument
Obj. It is still not a "method" in the result.

> it behaves the same manner? I.e.,
> the childs have full access to the methods and can even override them? 

This is confused.

1. In Ada access is based on visibility, which in turn rely on the packages
structure, not types.

2. Inheritance and overriding is related to tagged types. You can always
derive from a type which view is tagged. (A type can be privately tagged,
but publicly not, from this type you cannot derive)

>>> So I need to fix the
>>> package.function_constructor call and use a call of type
>>> object.method_constructor.
>> 
>> Why?
> 
> Well, the prefixed notation if I understood well was made exactly for
> filling this.

Prefix notation works only if you have the first argument of tagged type.
The questions are why do you need an argument which is null? Why do you
need access types at all. It does not look how things are usually done in
Ada.

>> What is wrong with the abstract factory pattern?
> 
> Nothing wrong. I'm not questioning this.

So why don't you use it?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2011-09-30 16:42 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-29 19:40 Constructors with multiple inheritance Rego, P.
2011-09-29 20:20 ` Dmitry A. Kazakov
2011-09-30  3:11   ` Rego, P.
2011-09-30  7:36     ` Dmitry A. Kazakov
2011-09-30 14:04       ` Rego, P.
2011-09-30 16:29         ` Robert A Duff
2011-09-30 19:14           ` Rego, P.
2011-09-30 16:42         ` Dmitry A. Kazakov [this message]
2011-09-30 19:42           ` Rego, P.
2011-10-06 12:46             ` Julian Leyh
2011-11-09  2:24           ` Rego, P.
2011-11-09  8:39             ` Dmitry A. Kazakov
2011-11-10  3:47               ` Rego, P.
2011-11-10  7:09                 ` AdaMagica
2011-11-10  7:20                   ` AdaMagica
2011-11-10  8:35                   ` Dmitry A. Kazakov
2011-11-12 15:16                     ` Rego, P.
2011-11-12 15:30                   ` Rego, P.
2011-11-12 16:28                     ` Dmitry A. Kazakov
2011-11-12 17:41                       ` Rego, P.
2011-11-10  8:33                 ` Simon Wright
2011-11-10  9:01                 ` Georg Bauhaus
2011-11-10  9:09                   ` Georg Bauhaus
2011-11-10 18:16                 ` Jeffrey Carter
2011-11-10 19:39                   ` Dmitry A. Kazakov
2011-11-09  9:00             ` Simon Wright
2011-11-10  3:54               ` Rego, P.
2011-10-07  0:08 ` Shark8
replies disabled

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