comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jere.groups@gmail.com>
Subject: Re: I'm facing an issue with: call to abstract procedure must be dispatching
Date: Wed, 9 Dec 2015 05:40:14 -0800 (PST)
Date: 2015-12-09T05:40:14-08:00	[thread overview]
Message-ID: <25d385ff-a7c6-40e8-bee0-9e465f92d98b@googlegroups.com> (raw)
In-Reply-To: <d674e44a-6341-4f73-903f-4bcee8406912@googlegroups.com>

On Tuesday, December 8, 2015 at 6:04:08 PM UTC-5, Serge Robyns wrote:
> On Tuesday, 8 December 2015 23:55:52 UTC+1, Jeffrey R. Carter  wrote:
> > If you don't need assignment because there will never be more than one of them,
> > that's an indication that you don't need a type and a variable; you need a
> > module. I suspect you think in terms of types because C++ only provides
> > encapsulation and information hiding through its class construct. In Ada, your
> > 1st thought when you want encapsulation or information hiding should be a pkg.
> > 
> 
> How do I then pass the context?  I mean, now I pass the parameter around.  through global variables?  Also in the future I would like to have multiple "tasks" running, each with their "context", especially the db session.  I do believe these are good reasons for having a variable.

If will be having multiple ones with their own contexts then you will have to use objects from types to do that.  However, if you are only going to have one, then as Jeffrey Carter suggested, just use a package.  A useless uncompiled example (I don't have GNAT in front of me here):

package My_Package is

   type Data_Type is record
      Value1 : Integer := Integer'First;
      Value2 : Positive := Positive'First;
   end record;

   procedure Update_My_Data(Data : in Data_Type);
   function  View_My_Data return Data_Type;

end My_Package;

   
package body My_Package is

   My_Data : Data_Type;

   procedure Update_My_Data(Data : in Data_Type) is
   begin
      My_Data := Data;
   end Update_My_Data;

   function  View_My_Data return Data_Type is
   begin
      return My_Data;
   end View_My_Data;

end My_Package;

My_Data is only accessible via the package body, so any clients have to use the provided functions of the package to manipulate or look at the data.  This example is over-simplistic, but I just wanted to show you the layout.  It's not the same as using a global since the clients can't access the variable directly and you have the freedom to have the public interface hide some implementation details on how the data is actually handled.

Since you are familiar with C++, it has a similar construct (I use it for peripherals in small embedded systems):  A class with only static members and static methods.  In this case, you are not using the class to generate objects but to organize methods and data with the ability to make some of them private (which you cannot do in a namespace) while also being able to retain a private non-global static state for one thing.  It is not as elegant as an Ada package and there are still some differences, but it is the closest analog to this that C++ has.

  parent reply	other threads:[~2015-12-09 13:40 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-08 16:45 I'm facing an issue with: call to abstract procedure must be dispatching Serge Robyns
2015-12-08 16:59 ` G.B.
2015-12-08 17:04 ` Dmitry A. Kazakov
2015-12-08 17:24   ` Serge Robyns
2015-12-08 17:42     ` Dmitry A. Kazakov
2015-12-08 18:00       ` Serge Robyns
2015-12-08 18:22         ` Dmitry A. Kazakov
2015-12-08 20:21           ` Serge Robyns
2015-12-08 21:08             ` Dmitry A. Kazakov
2015-12-08 21:55               ` Serge Robyns
2015-12-08 22:43                 ` Serge Robyns
2015-12-08 22:55                   ` Jeffrey R. Carter
2015-12-09 23:03                     ` Randy Brukardt
2015-12-10  8:38                       ` Serge Robyns
2015-12-10 23:43                         ` Randy Brukardt
2015-12-09  8:48                 ` Dmitry A. Kazakov
2015-12-09 10:53               ` G.B.
2015-12-09 12:03                 ` Dmitry A. Kazakov
2015-12-09 13:42                   ` G.B.
2015-12-09 14:23                     ` Dmitry A. Kazakov
2015-12-08 22:55             ` Jeffrey R. Carter
2015-12-08 23:04               ` Serge Robyns
2015-12-08 23:42                 ` Jeffrey R. Carter
2015-12-09 13:40                 ` Jere [this message]
2015-12-09 13:48                   ` G.B.
2015-12-09 15:33                     ` Jere
2015-12-13 21:37                 ` Shark8
2015-12-14  2:20                   ` Jeffrey R. Carter
2015-12-15  7:26                     ` Shark8
2015-12-08 17:30 ` Jeffrey R. Carter
2015-12-08 17:48   ` Serge Robyns
2015-12-08 18:46     ` Jeffrey R. Carter
2015-12-08 20:28       ` Serge Robyns
2015-12-08 22:20     ` Simon Wright
replies disabled

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