comp.lang.ada
 help / color / mirror / Atom feed
* Help with project
@ 1999-04-18  0:00 bob
  1999-04-19  0:00 ` Stephen Leake
  0 siblings, 1 reply; 3+ messages in thread
From: bob @ 1999-04-18  0:00 UTC (permalink / raw)


Hi, I am having a problem in trying to implement a program that
simulates
a waiting line queue in an airport, the workers are stored in an array
of
records, (the record will be the agent), each agent has a pointer to
their
line(type line_access),
			

I must declare a record for a customer in the generic spec , and
instantiate it in our source code, inside this record will be info
about
the customer(time in queue, etc),
now, below in the private area, I have
 PRIVATE
  TYPE line;
  TYPE line_access IS ACCESS line; 
  TYPE line IS RECORD 
        info: X;
        Next: line_access;      
  END RECORD;

TYPE Agent IS RECORD
      	Head:line_access;
          cur_cust:line_access;
          free_time:Integer;
	   etc(things for the agent)     
END RECORD;

where X is the customer record which will instantiated
the problem is, i have subprograms in the source that wont compile
because
i cant access agent or any of its fields, unless i go through the
spec.
some of the subprograms are , checkagents-see if they are done
servicing
cur_cust
addtoqueue-adds a cust
removefromqueue-removes from head of link list, assigns that one to
cur_cust

if i put the subprograms to the body, then it cant find the fields for
the
customer
do u have any ideas what to do?

thanks for taking the time to read this
jarrod

Please reply to....

rossjar@db.erau.edu






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

* Re: Help with project
  1999-04-18  0:00 Help with project bob
@ 1999-04-19  0:00 ` Stephen Leake
  1999-04-20  0:00   ` Ehud Lamm
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Leake @ 1999-04-19  0:00 UTC (permalink / raw)


rross@postoffice.ptd.net (bob) writes:

> I must declare a record for a customer in the generic spec , and
> instantiate it in our source code, inside this record will be info
> about
> the customer(time in queue, etc),
> now, below in the private area, I have
>  PRIVATE
>   TYPE line;
>   TYPE line_access IS ACCESS line; 
>   TYPE line IS RECORD 
>         info: X;
>         Next: line_access;      
>   END RECORD;
> 
> TYPE Agent IS RECORD
>       	Head:line_access;
>           cur_cust:line_access;
>           free_time:Integer;
> 	   etc(things for the agent)     
> END RECORD;
> 
> where X is the customer record which will instantiated
> the problem is, i have subprograms in the source that wont compile
> because
> i cant access agent or any of its fields, unless i go through the
> spec.

One suggestion is to simply not make anything private, until you've
got everything working. Then go back and see how you can arrange
things nicely into packages. Normally, this is not a good way to
design a system, but while you're still learning a language, it helps
to just write lots of working code.

> 
> if i put the subprograms to the body, then it cant find the fields for
> the
> customer
> do u have any ideas what to do?

You can add subprograms to the spec to provide access to the fields
you need:

procedure Set_free_time (Time : in Integer; Object : in out Agent);

-- Stephe




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

* Re: Help with project
  1999-04-19  0:00 ` Stephen Leake
@ 1999-04-20  0:00   ` Ehud Lamm
  0 siblings, 0 replies; 3+ messages in thread
From: Ehud Lamm @ 1999-04-20  0:00 UTC (permalink / raw)


> rross@postoffice.ptd.net (bob) writes:
> 
> > I must declare a record for a customer in the generic spec , and
> > instantiate it in our source code, inside this record will be info
> > about
> > the customer(time in queue, etc),
> > now, below in the private area, I have
> >  PRIVATE
> >   TYPE line;
> >   TYPE line_access IS ACCESS line; 
> >   TYPE line IS RECORD 
> >         info: X;
> >         Next: line_access;      
> >   END RECORD;
> > 
> > TYPE Agent IS RECORD
> >       	Head:line_access;
> >           cur_cust:line_access;
> >           free_time:Integer;
> > 	   etc(things for the agent)     
> > END RECORD;
> > 
> > where X is the customer record which will instantiated
> > the problem is, i have subprograms in the source that wont compile
> > because
> > i cant access agent or any of its fields, unless i go through the
> > spec.

Right!

This is the point of splitting the code into a spec and a body. You
achieve language enforced data hiding. This is very useful, when you get
to know it well, but can be combersome at first.

I think you should keep these two concepts in mind: interface and
implimentation.

The interface of a package is all the information other wiil need, and you
are willing to share. 

The implimenation details are your private secrets.

When you start thinking about desiging a package, you should ask yourself
what the user of the packger (that will be your main program) will need to
do. Than you take this list, and from it decide what you have to include
in your interface. 

From this you can later deduce the implimetation details - or actually if
your interface is good, you will have a lot of freedom in deciding on the
implimenation details.

Note that going this route can still lead you to bad design. After
designing the interface you should check to see if it makes sense. Some
things that are good to check are: consistency (is there any "logical"
connection between all the routines you supply), completeness (can the
user really do what needs to be done with the package?), simplicity etc.

Try it.
It is not all that hard, after your first couple of packages. 

If you want to get a good feel into this, I suggest you do two things:
(1) look at example code.
    There are many links on my web page - in the misc. links section

(2) read some articles about design etc.
    I suggest you look at my web page's "suggested online reading". 
    I'd recommend Parnas for general feeling of what "data hiding" is, and
perhaps Garlan & Shaw on architecture to give you a better feel of the
high level issue.

Enjoy!

Ehud Lamm     mslamm@pluto.mscc.huji.ac.il
http://www2.cybercities.com/e/ehud/ada





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

end of thread, other threads:[~1999-04-20  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-18  0:00 Help with project bob
1999-04-19  0:00 ` Stephen Leake
1999-04-20  0:00   ` Ehud Lamm

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