SlideShare una empresa de Scribd logo
1 de 90
Descargar para leer sin conexión
Franco Gasperoni
                             gasperon@act-europe.fr
                             http://libre.act-europe.fr

                                                                                           1
http://libre.act-europe.fr         © ACT Europe under the GNU Free Documentation License
Copyright Notice

           • © ACT Europe under the GNU Free Documentation License

           • Permission is granted to copy, distribute and/or modify this
             document under the terms of the GNU Free Documentation
             License, Version 1.1 or any later version published by the Free
             Software Foundation; provided its original author is mentioned
             and the link to http://libre.act-europe.fr/ is kept at the bottom of
             every non-title slide. A copy of the license is available at:
           •                          http://www.fsf.org/licenses/fdl.html




                                                                                            2
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
3
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
What is the largest
                              software system
                              you have built ?

                                 (in SLOC)



                                                                                         4
http://libre.act-europe.fr       © ACT Europe under the GNU Free Documentation License
Small Software Systems

           • Understandable by 1 person

           • Can throw away & replace it to
                  – repair / extend
                  – port to new platform

           • Anything is OK for small systems (< 10 Ksloc)


                                                                                        5
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
Medium/Large Systems

           • Team of people
           • No 1 person knows all its aspects
           • Long life-span (> 10 years)
           • CANNOT throw away & replace it to
                  – repair / extend
                  – port to new platform


           • Requires organization, discipline & right tools
                                                                                        6
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
• Programming in the Large
                             – specification & implementation
                             – privacy
                             – abstract data types
                             – hierarchical packages




                                                                                            7
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
Separate Compilation
       T
                               C
       H                       O
                               D        Compiler                          object
       E                       E



                                                                                               L
                               C                                                               i
       P                       O
                               D        Compiler                          object               n     executable
                                                                                               k
       R                       E
                                                                                               e
       O                                                                                       r

       B
       L                           C
                                   O
                                           Compiler                          object
       E                           D
                                   E                                                               libraries
       M                                                                                                       8
http://libre.act-europe.fr             © ACT Europe under the GNU Free Documentation License
Problem with this approach
                                 C              C
                                                O                 C
                                 O                                O
                                 D              D
                                                E                 D
                             C   E                                E
                             O
                             D           C
                             E           O
                                         D
                                         E

                                                             • No structure

                                                             • To write your own code
                                                                      – YOU MUST understand
                                                                        everybody else’s code



                                                                                                9
http://libre.act-europe.fr       © ACT Europe under the GNU Free Documentation License
Idea
                              SPECIFY
                             WHAT EACH
                              MODULE
                             SHOULD DO




                                                                                       10
http://libre.act-europe.fr     © ACT Europe under the GNU Free Documentation License
SPECIFICATION




                                      ?
                                BODY                                            Software module
                                                                                                  11
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
• Programming in the Large
                             – specification & implementation
                               • specification
                               • implementation
                               • specification rules in Ada




                                                                                             12
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
A Specification is a ...

                                                                                           Users/clients
      Implementor                                                                          of the
      of the                                                                               module
      module
                                 CONTRACT


           • On the SERVICES provided by the module



                                                                                                     13
http://libre.act-europe.fr         © ACT Europe under the GNU Free Documentation License
• SPEC = list of services provided

       • BODY = implementation of the services (hidden)


                               Service_1
                               Service_2
                               Service_3
                             Service_1
                                 implementation

                             Service_2
                                 implementation

                             Service_3
                                 implementation
                                                                Software module                   14
http://libre.act-europe.fr                © ACT Europe under the GNU Free Documentation License
SPECIFICATION




                                             ?
                                         BODY                                        15
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
Example

           • Create a Queue module that can
                  – Add an Integer to the Queue
                  – See the First integer in the Queue
                  – Get the first integer in the Queue
                  – Test whether the Queue is Empty



                                                                                        16
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
queue.ads
          queue.ads
                    package Queue is
                    package Queue is
                       procedure Add (Element ::Integer);
                       procedure Add (Element Integer);

                              function First return Integer;
                             function First return Integer;
                              function Get return Integer;
                             function Get return Integer;

                        function Empty return Boolean;
                       function Empty return Boolean;
                    end Queue;
                    end Queue;




                                                                                                17
http://libre.act-europe.fr              © ACT Europe under the GNU Free Documentation License
queue.ads
                                                                            queue.ads
                              package Queue is
                             package Queue is
                                procedure Add (Element : :Integer);
                                 procedure Add (Element Integer);

                                 function First return Integer;
                                function First return Integer;
                                 function Get return Integer;
                                function Get return Integer;

                                 function Empty return Boolean;
                                function Empty return Boolean;
                              end Queue;
                             end Queue;




                                                ?
                                           BODY                                                   package Queue
                                                                                                                  18
http://libre.act-europe.fr                © ACT Europe under the GNU Free Documentation License
Using package Queue
                         client.adb
                                with Queue;
                                procedure Client is
                                   Queue_Error : exception;
                                   X : Integer;
                                begin
                                   Queue.Add (3);
                                   Queue.Add (4);

                                  if not Queue.Empty then
                                      X := Queue.Get;
                                  else
                                      raise Queue_Error;
                                  end if;
                                end Client;
                                                                                              19
http://libre.act-europe.fr            © ACT Europe under the GNU Free Documentation License
Specifications Reduce Complexity
                                      SPEC
                                     SPEC
                              SPEC
                             SPEC       SPEC
                                       SPEC
                                SPEC
                               SPEC




                                                                    • To write your own code
                                                                             – only need to understand
                                                                               specs for the services
                                                                               you need




                                                                                                     20
http://libre.act-europe.fr              © ACT Europe under the GNU Free Documentation License
To write Client only need to look at
                                                                             queue.ads
                                                                            queue.ads
                              package Queue is
                             package Queue is
                                procedure Add (Element : :Integer);
                                 procedure Add (Element Integer);

                                 function First return Integer;
                                function First return Integer;
                                 function Get return Integer;
                                function Get return Integer;

                                 function Empty return Boolean;
                                function Empty return Boolean;
                              end Queue;
                             end Queue;




                                                ?                                                package Queue
                                                                                                                 21
http://libre.act-europe.fr               © ACT Europe under the GNU Free Documentation License
Aside: use clause
                             with Queue; use Queue;
                             procedure Client is
                                Queue_Error : exception;
                                X : Integer;
                             begin
                                Queue. Add (3);
                                Queue. Add (4);

                               if not Queue. Empty then
                                   X := Queue. Get;
                               else
                                   raise Queue_Error;
                               end if;
                             end Client;
                                                                                          22
http://libre.act-europe.fr        © ACT Europe under the GNU Free Documentation License
• Programming in the Large
                             – specification & implementation
                               • specification
                               • implementation
                               • specification rules in Ada




                                                                                             23
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
ONE possible
                             implementation
                               of package
                                  Queue

                               This implementation
                             raises Constraint_Error
                             if more than Max_Size
                         elements are put in the Queue.

                                                                                          24
http://libre.act-europe.fr        © ACT Europe under the GNU Free Documentation License
Circular Buffer


     Q

                   0         1
                                                                                             Max_Size - 1


                                 Q_Last                             Q_First



                                                                                                       25
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
queue.adb
           package body Queue is
              Max_Size : constant := 100;

                  type Q_Index is mod Max_Size;
                  Q : array (Q_Index range 0 .. Max_Size - 1) of Integer;

                  Q_First : Q_Index := Q ’ First;
                  Q_Last : Q_Index := Q_First;
                  Size    : Natural range 0 .. Max_Size;

                    procedure Add (Element : Integer) is
                    begin
                           Q (Q_Last) := Element;
                           Q_Last := Q_Last + 1;
                           Size := Size + 1;
                    end Add;
                    ...                                                                             26
             end Queue;
http://libre.act-europe.fr             © ACT Europe under the GNU Free Documentation License
package body Queue is          queue.adb
                                ...
                                function First return Integer is
                                begin
                                    return Q (Q_First);
                                end First;
                                 function Get return Integer is
                                 begin
                                    Q_First := Q_First + 1;
                                    Size := Size - 1;
                                    return Q (Q_First - 1);
                                 end Get;

                                function Empty return Boolean is
                                begin
                                   return Size = 0;
                                end Empty;                                         27
http://libre.act-europe.fr   end Queue; under the GNU Free Documentation License
                                     © ACT Europe
ANOTHER possible
                              implementation
                                of package
                                   Queue



                                                                                         28
http://libre.act-europe.fr       © ACT Europe under the GNU Free Documentation License
Linked List




              Q_First                                    Q_Last




                 Free                                                                29
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
queue.adb
                  package body Queue is
                     type Queue_Element;
                     type Element_Ptr is access Queue_Element;

                             type Queue_Element is record
                                Val : Integer;
                                Next : Element_Ptr;
                             end record;

                             Q_First : Element_Ptr;
                             Q_Last : Element_Ptr;

                     Free : Element_Ptr := new Queue_Element;
                     ...
                  end Queue;
                                                                                                             30
http://libre.act-europe.fr               © ACT Europe under the GNU Free Documentation License
queue.adb
             package body Queue is
                    ...
                    procedure Add (Element : Integer) is
                    begin
                           if Q_First = null then
                               Q_First := Free;
                           else
                               Q_Last.Next := Free;
                           end if;
                           Q_Last := Free;
                           Free := Free.Next;
                           Q_Last.all := (Element, null);
                           if Free = null then
                               Free := new Queue_Element;
                           end if;
                    end Add;
                    ...                                                                         31
             end Queue;
http://libre.act-europe.fr              © ACT Europe under the GNU Free Documentation License
queue.adb
                             package body Queue is
                                ...
                                function Get return Integer is
                                    Tmp : Element_Ptr := Q_First;
                                begin
                                    Q_First := Q_First.Next;
                                    if Q_First = null then
                                        Q_Last := null;
                                    end if;
                                    Tmp.Next := Free;
                                    Free := Tmp;
                                    return Tmp.Val;
                                end Get;
                                ...
                             end Queue;
                                                                                             32
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
queue.adb
                             package body Queue is
                                ...
                                function First return Integer is
                                begin
                                    return Q_First;
                                end First;
                               function Empty return Boolean is
                                begin
                                  return Q_First = null;
                                end Empty;
                             end Queue;
                                                                                                         33
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
A Spec can have several
                                     implementations
             queue.ads
           queue.ads
                    package Queue is
                  package Queue is (Element : Integer);
                       procedure Add
                     procedure Add (Element : Integer);
                       function First return Integer;
                     function First return Integer;
                       function Get return Integer;
                     function Get return Integer;
                       function Empty return Boolean;
                     function Empty return Boolean;
                    end Queue;
                  end Queue;




                                                                                • Can change implementation
                                                 second
                                                second
       first
      first                                    implement.
                                              implement.
    implement.
   implement.                                                                   • WITHOUT having to change
                                                                                  ANY of the client’s code


                                                                                                                    34
http://libre.act-europe.fr                                  © ACT Europe under the GNU Free Documentation License
• Programming in the Large
                             – specification & implementation
                               • specification
                               • implementation
                               • specification rules in Ada




                                                                                             35
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
In Ada

           • Spec always checked against implementation

           • Must with the specs that you are going to
                use (not in C)
           • Packages provide multiple name spaces




                                                                                         36
http://libre.act-europe.fr       © ACT Europe under the GNU Free Documentation License
Spec is checked against its body
                    package Queue is
                    package Queue is
                       procedure Add (Element ::Integer);
                        procedure Add (Element Integer);
                        ...
                       ...
                    end Queue;
                    end Queue;                          Compilation
                                                                                          error
                    package body Queue is
                    package body Queue is
                        ...
                       ...
                       procedure Add (Element ::Integer; X ::Float) is
                        procedure Add (Element Integer; X Float) is
                             ...
                            ...
                        end Add;
                       end Add;
                        ...
                       ...
                    end Queue;
                    end Queue;
                                                                                                  37
http://libre.act-europe.fr        © ACT Europe under the GNU Free Documentation License
Must with Specs used


                              with Queue;
                              procedure Client is                                            Compilation
                                 ...                                                           error
                              begin
                                 Queue.Add (3);
                                 ...
                              end Client;




                                                                                                           38
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
Multiple Name Spaces
         package Queue is
        package Queue is                                        package Set is
                                                               package Set is
           procedure Add (E ::Integer);
            procedure Add (E Integer);                            procedure Add (E ::Integer);
                                                                   procedure Add (E Integer);
            ...
           ...                                                     ...
                                                                  ...
         end Queue;
        end Queue;                                              end Set;
                                                               end Set;




                                 with Queue;
                                 with Set;
                                 procedure Client is
                                 begin
                                    Queue.Add (3);

                                   Set.Add (99);
                                 end Client;                                                 39
http://libre.act-europe.fr         © ACT Europe under the GNU Free Documentation License
Use Clause and Ambiguities
         package Queue is
        package Queue is                                    package Set is
                                                           package Set is
           procedure Add (E ::Integer);
            procedure Add (E Integer);                        procedure Add (E ::Integer);
                                                               procedure Add (E Integer);
            ...
           ...                                                 ...
                                                              ...
         end Queue;
        end Queue;                                          end Set;
                                                           end Set;




                             with Queue; use Queue;
                             with Set;   use Set;
                             procedure Client is
                             begin                  Compilation
                                Add (123);            error
                             end Client;             ambiguity

                                                                                         40
http://libre.act-europe.fr     © ACT Europe under the GNU Free Documentation License
But … Ada has overloading
         package Queue is
        package Queue is
           procedure Add (E ::Integer);
            procedure Add (E Integer);
           procedure Add (E ::Float);
            procedure Add (E Float);
            ...
           ...
         end Queue;
        end Queue;


                             with Queue; use Queue;

                             procedure Client is
                             begin
                                Add (123);

                               Add (3.141);
                             end Client;                                               41
http://libre.act-europe.fr     © ACT Europe under the GNU Free Documentation License
• Programming in the Large
                             – specification & implementation
                             – privacy
                             – abstract data types
                             – hierarchical packages




                                                                                            42
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
Having Several Queues

                    package Queues is
                    package Queues is
                        type Queue is …;
                       type Queue is …;

                       procedure Add (Q ::Queue; Element ::Integer);
                        procedure Add (Q Queue; Element Integer);
                       function First (Q ::Queue) return Integer;
                        function First (Q Queue) return Integer;
                       function Get (Q :: Queue) return Integer;
                        function Get (Q Queue) return Integer;
                       function Empty (Q ::Queue) return Boolean;
                        function Empty (Q Queue) return Boolean;
                    end Queues;
                    end Queues;




                                                                                          43
http://libre.act-europe.fr        © ACT Europe under the GNU Free Documentation License
!!! WARNING !!!

                    package Queues is
                    package Queues is

                              type Queue is …;                                       Use Different names
                             type Queue is …;




                    end Queues;
                    end Queues;




                                                                                                      44
http://libre.act-europe.fr             © ACT Europe under the GNU Free Documentation License
Using Several Queues
                                with Queues; use Queues;
                                procedure Client is
                                   Q1 : Queue;
                                   Q2 : Queue;

                                begin
                                  Add (Q1, 123);

                                  Add (Q2, 3);

                                  Add (Q2, Get (Q1));
                                end Client;
                                                                                           45
http://libre.act-europe.fr         © ACT Europe under the GNU Free Documentation License
One possible implementation ...
                                                             type Q_Element;
                                                            type Q_Element;
                                                             type Element_Ptr is
                                                            type Element_Ptr is
                                                                access Queue_Element;
                                                               access Queue_Element;
                                                             type Queue_Element is record
                                                            type Queue_Element is record
                                                               Val ::Integer;
                                                                Val Integer;
                                                               Next ::Element_Ptr;
                                                                Next Element_Ptr;
                                                             end record;
                                                            end record;
package Queues is
   type Queue is …;                               type Queue is record
                                                 type Queue is record
                                                    First ::Element_Ptr;
                                                     First Element_Ptr;
      procedure Add (Q : Queue; Element : Integer); Last : Element_Ptr;
      function First (Q : Queue) return Integer;    Last : Element_Ptr;
                                                  end record;
      function Get (Q : Queue) return Integer; end record;
   function Empty (Q : Queue) return Boolean;
end Queues;




                                                                                        46
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
Client code allowed to depend
                on the implementation !
                             with Queues; use Queues;
                             procedure Client is
                                Q1 : Queue;
                                Q2 : Queue;

                             begin
                               Add (Q1, 123);
                               Add (Q2, 3);

                                Q2.Last := null;                                         OK

                             end Client;
                                                                                              47
http://libre.act-europe.fr       © ACT Europe under the GNU Free Documentation License
Another implementation ...

                                                      Max_Size ::constant := 100;
                                                       Max_Size constant := 100;
                                                       type Q_array (Natural range <>)
                                                      type Q_array (Natural range <>)
                                                          of Integer;
                                                         of Integer;
                                              type Queue is record
                                             type Queue is record
                                                Q ::Q_Array (0 .. Max_Size);
                                                 Q Q_Array (0 .. Max_Size);
package Queues is                               First ::Natural;
                                                 First Natural;
   type Queue is …;
                                                Last ::Natural;
                                                 Last Natural;
   procedure Add (Q : Queue; Element : Integer);Size ::Natural;
                                                 Size Natural;
                                              end record;
   function First (Q : Queue) return Integer;end record;
   function Get (Q : Queue) return Integer;
   function Empty (Q : Queue) return Boolean;
end Queues;




                                                                                      48
http://libre.act-europe.fr    © ACT Europe under the GNU Free Documentation License
… breaks client code !

                                 with Queues; use Queues;
                                 procedure Client is
                                    Q1 : Queue;
                                    Q2 : Queue;

                                 begin
                                   Add (Q1, 123);
                                   Add (Q2, 3);
                                                                                             Compilation
                                                                                               error
                                    Q2.Last := null;

                                 end Client;
                                                                                                           49
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
Even without changing
                               the implementation
                              there is a PROBLEM
                                with Queues; use Queues;
                                procedure Client is
                                   Q1 : Queue;
                                   Q2 : Queue;

                                begin
                                  Add (Q1, 123);                                            Q2:
             Q2 is in an                                                                                    3
                                                                                                            3
            inconsistent
                                  Add (Q2, 3);
                                                                                             First
                state                                                                        Last
                                   Q2.Last := null;

                                end Client;                                                          null   50
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
You need PRIVACY

           • Exposing your data structures is risky

                  – Client code may manipulate the structures
                    directly without using your own services

                  – Client code is hard to change



                                                                                         51
http://libre.act-europe.fr       © ACT Europe under the GNU Free Documentation License
Think                  BIG
                               what if
                         the Queues package
                      is used by 1000s of other
                              packages

                                                                                      52
http://libre.act-europe.fr    © ACT Europe under the GNU Free Documentation License
• If there is a bug concerning a Queue, you
        may have to look at 1000s of packages to
        find the bug



      • If you change the implementation you
        may have to update 1000s of packages



                                                                                     53
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
• Programming in the Large

                             – privacy
                               • private types
                               • private types & discriminants
                               • limited private types




                                                                                            54
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
Private types

                    package Queues is
                    package Queues is
                        type Queue is private;
                       type Queue is private;
                             procedure Add (Q ::Queue; Element ::Integer);
                              procedure Add (Q Queue; Element Integer);
                             function First (Q ::Queue) return Integer;
                              function First (Q Queue) return Integer;
                             function Get (Q :: Queue) return Integer;
                              function Get (Q Queue) return Integer;
                             function Empty (Q ::Queue) return Boolean;
                              function Empty (Q Queue) return Boolean;
                    private
                    private
                         type Queue is …;
                        type Queue is …;
                    end Queues;
                    end Queues;




                                                                                               55
http://libre.act-europe.fr             © ACT Europe under the GNU Free Documentation License
In any implementation ...
                             package Queues is
                                type Queue is private;
                                procedure Add (Q : Queue; Element : Integer);
                                function First (Q : Queue) return Integer;
                                function Get (Q : Queue) return Integer;
                                function Empty (Q : Queue) return Boolean;
                             private
                                 type Queue_Element;
                                 type Element_Ptr is access Queue_Element;
                                 type Queue_Element is record
                                     Val : Integer;
                                     Next : Element_Ptr;
                                 end record;
                                type Queue is record
                                   First : Element_Ptr;
                                   Last : Element_Ptr;
                                end record;
                             end Queues;                                                           56
http://libre.act-europe.fr                 © ACT Europe under the GNU Free Documentation License
… private types are PRIVATE

                             with Queues; use Queues;
                             procedure Client is
                                Q1 : Queue;
                                Q2 : Queue;

                             begin
                               Add (Q1, 123);
                               Add (Q2, 3);
                                                                                         Compilation
                                Q2.Last := null;                                           error

                             end Client;
                                                                                                       57
http://libre.act-europe.fr       © ACT Europe under the GNU Free Documentation License
Advantages of private types

           • Enforces the contract of a specification

           • No client code can corrupt your data structures

           • Can change implementation without changing
             client code



                                                                                     58
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
Why is the private part in the spec ?
                             package Queues is
                                type Queue is private;
                                   procedure Add (Q : Queue; Element : Integer);
                                   function First (Q : Queue) return Integer;
                                   function Get (Q : Queue) return Integer;
                                   function Empty (Q : Queue) return Boolean;
                             private
                                 type Queue_Element;
                                 type Element_Ptr is access Queue_Element;
                                 type Queue_Element is record
                                     Val : Integer;
                                     Next : Element_Ptr;
                                 end record;
                                type Queue is record
                                   First : Element_Ptr;
                                   Last : Element_Ptr;
                                end record;
                             end Queues; © ACT Europe under the GNU Free Documentation License   59
http://libre.act-europe.fr
… because we still need to
                    compile the clients code
                             with Queues; use Queues;

                             procedure Client is

                                Q1 : Queue;

                             begin
                               Add (Q1, 123);
                             end Client;



                                                                                         60
http://libre.act-europe.fr       © ACT Europe under the GNU Free Documentation License
… but you can make a private type
              quite private

                     package Queues is
                        type Queue is private;
                             procedure Add (Q : Queue; Element : Integer);
                             function First (Q : Queue) return Integer;
                             function Get (Q : Queue) return Integer;
                             function Empty (Q : Queue) return Boolean;
                     private
                         type Queue_Info;
                         type Queue is access Queue_Info;
                     end Queues;

                                                                                               61
http://libre.act-europe.fr             © ACT Europe under the GNU Free Documentation License
package body Queues is
                                type Queue_Element;
                                type Element_Ptr is access Queue_Element;

                                type Queue_Element is record
                                   Val : Integer;
                                   Next : Element_Ptr;
                                end record;
                                type Queue_Info is record
                                    First : Element_Ptr;
                                    Last : Element_Ptr;
                                end record;
                                ...
                             end Queues;
                                                                                               62
http://libre.act-europe.fr             © ACT Europe under the GNU Free Documentation License
• Programming in the Large

                             – privacy
                               • private types
                               • private types & discriminants
                               • limited private types




                                                                                            63
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
package Queues is
                     type Queue (Max_Size : Natural) is private;

                             procedure Add (Q : Queue; Element : Integer);
                             function First (Q : Queue) return Integer;
                             function Get (Q : Queue) return Integer;
                             function Empty (Q : Queue) return Boolean;
                  private
                      type Q_array (Natural range <>) of Integer;

                     type Queue (Max_Size : Natural) is record
                        Q : Q_Array (0 .. Max_Size);
                        First : Natural;
                        Last : Natural;
                        Size : Natural;
                     end record;
                  end Queues;                                                                   64
http://libre.act-europe.fr              © ACT Europe under the GNU Free Documentation License
with Queues; use Queues;
                         procedure Client is

                             Q1 : Queue (100);                       Q1 can have up to 100 elmts

                             Q2 : Queue (250);                    Q2 can have up to 250 elmts

                         begin
                           Add (Q1, 123);

                           Add (Q2, 3);
                         end Client;


                                                                                              65
http://libre.act-europe.fr            © ACT Europe under the GNU Free Documentation License
• Programming in the Large

                             – privacy
                               • private types
                               • private types & discriminants
                               • limited private types




                                                                                            66
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
with Queues; use Queues;
                             procedure Client is
                                Q1 : Queue;
                                Q2 : Queue;

                               X : Integer;

                             begin
                               Add (Q1, 123);
                               Add (Q1, 3);                                     Does this affect Q1 ?

                               Q2 := Q1;

                               X := Get (Q2);
                             end Client;

                                                                                                    67
http://libre.act-europe.fr             © ACT Europe under the GNU Free Documentation License
it depends on … the
                                implementation !

           • If a Queue is implemented with

                  – a pointer then Get (Q2) MODIFIES Q1


                  – a record containing an array then
                     Get (Q2) does NOT modify Q1



                                                                                          68
http://libre.act-europe.fr        © ACT Europe under the GNU Free Documentation License
with Queues; use Queues;                                         Pointer
   procedure Client is                                             Pointer
      Q1 : Queue;                                               implementation
                                                               implementation
      Q2 : Queue;
      X : Integer;
   begin
                            Q1:                                       123
                                                                     123
      Add (Q1, 123);

          Add (Q1, 3);                                                123                   3
                                           Q1:                       123                    3


          Q2 := Q1;                          Q2:

                                                          Q1:                         123
                                                                                     123        3
                                                                                                3
     X := Get (Q2);
   end Client;                                              Q2:
                                                                                                    69
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
limited private types



           • NO assignment                                :=

           • NO equality comparison                                                       =
                                                                                              70
http://libre.act-europe.fr        © ACT Europe under the GNU Free Documentation License
package Queues is
                    package Queues is
                        type Queue is limited private;
                       type Queue is limited private;
                             procedure Add (Q ::Queue; Element ::Integer);
                              procedure Add (Q Queue; Element Integer);
                             function First (Q ::Queue) return Integer;
                              function First (Q Queue) return Integer;
                             function Get (Q :: Queue) return Integer;
                              function Get (Q Queue) return Integer;
                             function Empty (Q ::Queue) return Boolean;
                              function Empty (Q Queue) return Boolean;
                    private
                    private
                         type Queue is …;
                        type Queue is …;
                    end Queues;
                    end Queues;




                                                                                               71
http://libre.act-europe.fr             © ACT Europe under the GNU Free Documentation License
with Queues; use Queues;
                             procedure Client is
                                Q1 : Queue;
                                Q2 : Queue;

                                X : Integer;

                             begin
                               Add (Q1, 123);
                               Add (Q1, 3);                                          COMPILATION
                                                                                        ERROR
                                Q2 := Q1;                                             := forbidden

                             end Client;
                                                                                                     72
http://libre.act-europe.fr              © ACT Europe under the GNU Free Documentation License
• Programming in the Large
                             – specification & implementation
                             – privacy
                             – abstract data types
                             – hierarchical packages




                                                                                            73
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
Queue is an
                             Abstract Data Type
                                   (ADT)


                              • Set of abstract values (data domain)
           ADT =
                              • collection of abstract Operations
                                (routines that manipulate the values)


                                                                                           74
http://libre.act-europe.fr         © ACT Europe under the GNU Free Documentation License
Queue is an ADT
                                                     values
                 package Queues is
                 package Queues is
                     type Queue is limited private;
                    type Queue is limited private;

                        procedure Add (Q ::Queue; Element ::Integer);
                         procedure Add (Q Queue; Element Integer);
                        function First (Q ::Queue) return Integer;
                         function First (Q Queue) return Integer;
                        function Get (Q :: Queue) return Integer;
                         function Get (Q Queue) return Integer;
                        function Empty (Q ::Queue) return Boolean;
                         function Empty (Q Queue) return Boolean;
                 private
                 private
                      type Queue is …;
                     type Queue is …;                                        operations
                 end Queues;
                 end Queues;                                                                75
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
Objects & Variables

                 • OBJECT = instance of an ADT
                        – piece of memory containing values of the ADT



                 • VARIABLE = name of a specific object


                 • not all objects have a name

                                                                                            76
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
an object



                   My_Q : Queue;
                                                                                               Queue
                                                                                               object



                             name of the object




                                                                                              Memory
                                                                                                        77
http://libre.act-europe.fr         © ACT Europe under the GNU Free Documentation License
not all objects have a name


        type Queue_Ptr is access Queue;                                                  Queue
                                                                                         object
        Ptr : Queue_Ptr;

        Ptr := new Queue;




                               object has no name
               Ptr is just a pointer to the object                                      Memory
                                                                                                  78
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
CLASS = ADT
                                   + inheritance




                                                                                          79
http://libre.act-europe.fr        © ACT Europe under the GNU Free Documentation License
operation                                                       invoke some
                                                                                               operation
                                                                                               in the SPEC
                               operation
                                                                                               to use ADT
                                                                                               services
                               operation

                             Private
                              data




                  ENCAPSULATION
                                                                                                         80
http://libre.act-europe.fr             © ACT Europe under the GNU Free Documentation License
The object model




                                                                                        81
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
The C model


                             GLOBAL DATA




               C module      C module                                                   C module 82
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
• Programming in the Large
                             – specification & implementation
                             – privacy
                             – abstract data types
                             – hierarchical packages




                                                                                            83
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
To add functionality ...
      function Last (Q : Queue) return Integer;

                  package Queues is
                     type Queue is private;
                             procedure Add (Q : Queue; Element : Integer);
                             function First (Q : Queue) return Integer;
                             function Get (Q : Queue) return Integer;
                             function Empty (Q : Queue) return Boolean;

                     function Last (Q : Queue) return Integer;
                  private
                      type Queue is …;                      Must add
                  end Queues;                                  it to
                                                              Queues
                    Queue is a private type                                                     84
http://libre.act-europe.fr              © ACT Europe under the GNU Free Documentation License
But ...

           • Every time you change a spec you must
             recompile all its clients

           • Every time you change a module you must
             RETEST the whole module




                                                                                     85
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
Solution: use child units
                                                                                        queues.ads
                             package Queues is
                                type Queue is private;
                                 procedure Add (Q : Queue; Element : Integer);
                                 function First (Q : Queue) return Integer;
                                 function Get (Q : Queue) return Integer;
                                 function Empty (Q : Queue) return Boolean;
                             private
                                 type Queue is …;
        Child                end Queues;
     subprogram

                                                    queues-last.ads
        function Queues . Last (Q : Queue) return Integer;

                                                                                              86
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
Child Units Rules

           • The body or private part of a child unit can
             see the private part of all of its parents



           • The spec of a child unit does NOT




                                                                                        87
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
Using a child unit

                             with Queues; use Queues;
                             with Queues.Last;
                             procedure Client is
                                Q : Queue;
                                X : Integer;

                             begin
                               Add (Q, 123);
                               Add (Q, 3);

                               X := Queues.Last (Q);
                             end Client;
                                                                                         88
http://libre.act-europe.fr       © ACT Europe under the GNU Free Documentation License
queues.ads
                             package Queues is
                                type Queue is private;
                                 procedure Add (Q : Queue; Element : Integer);
                                 function First (Q : Queue) return Integer;
                                 function Get (Q : Queue) return Integer;
                                 function Empty (Q : Queue) return Boolean;
                             private
                                 type Queue is …;
                             end Queues;


           Child
          package
                                                            queues-new_functionality.ads
        package Queues . New_Functionality is
          function Last (Q : Queue) return Integer;
        end Queues . New_Functionality
                                                                                                  89
http://libre.act-europe.fr         © ACT Europe under the GNU Free Documentation License
with Queues; use Queues;
                         with Queues.New_Functionality;
                         procedure Client is
                            Q : Queue;
                            X : Integer;

                         begin
                           Add (Q, 123);
                           Add (Q, 3);

                           X := Queues.New_Functionality.Last (Q);
                         end Client;

                                                                                            90
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License

Más contenido relacionado

Destacado

GNAT Pro User Day: Ada Factory
GNAT Pro User Day: Ada FactoryGNAT Pro User Day: Ada Factory
GNAT Pro User Day: Ada FactoryAdaCore
 
GNAT Pro User Day: New and Upcoming Developments in the AdaCore Technology
GNAT Pro User Day: New and Upcoming Developments in the AdaCore TechnologyGNAT Pro User Day: New and Upcoming Developments in the AdaCore Technology
GNAT Pro User Day: New and Upcoming Developments in the AdaCore TechnologyAdaCore
 
ADA programming language
ADA programming languageADA programming language
ADA programming languageAisha Kalsoom
 
Ada Seminar — An Introduction to Ada
Ada Seminar — An Introduction to AdaAda Seminar — An Introduction to Ada
Ada Seminar — An Introduction to AdaAdrian Hoe
 
Ada 2012
Ada 2012Ada 2012
Ada 2012AdaCore
 
Euclid and his contribution in development of math
Euclid and his contribution in development of mathEuclid and his contribution in development of math
Euclid and his contribution in development of mathAkshay Kumar
 
Evolution of Programming Languages
Evolution of Programming LanguagesEvolution of Programming Languages
Evolution of Programming LanguagesSayanee Basu
 

Destacado (10)

GNAT Pro User Day: Ada Factory
GNAT Pro User Day: Ada FactoryGNAT Pro User Day: Ada Factory
GNAT Pro User Day: Ada Factory
 
GNAT Pro User Day: New and Upcoming Developments in the AdaCore Technology
GNAT Pro User Day: New and Upcoming Developments in the AdaCore TechnologyGNAT Pro User Day: New and Upcoming Developments in the AdaCore Technology
GNAT Pro User Day: New and Upcoming Developments in the AdaCore Technology
 
ADA programming language
ADA programming languageADA programming language
ADA programming language
 
Ada Seminar — An Introduction to Ada
Ada Seminar — An Introduction to AdaAda Seminar — An Introduction to Ada
Ada Seminar — An Introduction to Ada
 
Ada 2012
Ada 2012Ada 2012
Ada 2012
 
Euclid and his contribution in development of math
Euclid and his contribution in development of mathEuclid and his contribution in development of math
Euclid and his contribution in development of math
 
High performance fibres
High performance fibresHigh performance fibres
High performance fibres
 
Evolution of Programming Languages
Evolution of Programming LanguagesEvolution of Programming Languages
Evolution of Programming Languages
 
Ada 2012
Ada 2012Ada 2012
Ada 2012
 
Euclid project
Euclid projectEuclid project
Euclid project
 

Similar a Ada 95 - Programming in the large

Keynote de Mike Milinkovich
Keynote de Mike MilinkovichKeynote de Mike Milinkovich
Keynote de Mike MilinkovichEclipseDayParis
 
Nokia and maemo in the new GNOME mobile context
 Nokia and maemo in the new GNOME mobile context Nokia and maemo in the new GNOME mobile context
Nokia and maemo in the new GNOME mobile contextqgil
 
I Diff 2008 conference IP-Racine Pictures
I Diff 2008 conference IP-Racine PicturesI Diff 2008 conference IP-Racine Pictures
I Diff 2008 conference IP-Racine PicturesBenoit Michel
 
EOLE / OWF 12 - Viral licences – myth or reality - patrice-emmanuel schmitz (...
EOLE / OWF 12 - Viral licences – myth or reality - patrice-emmanuel schmitz (...EOLE / OWF 12 - Viral licences – myth or reality - patrice-emmanuel schmitz (...
EOLE / OWF 12 - Viral licences – myth or reality - patrice-emmanuel schmitz (...Paris Open Source Summit
 
What is new in Helios
What is new in HeliosWhat is new in Helios
What is new in HeliosTomasz Zarna
 
"European Commission Open Source Observatory and Repository Project" by Ismae...
"European Commission Open Source Observatory and Repository Project" by Ismae..."European Commission Open Source Observatory and Repository Project" by Ismae...
"European Commission Open Source Observatory and Repository Project" by Ismae...eLiberatica
 
Ontology Aware Applications @ YAPC::EU 2012
Ontology Aware Applications @ YAPC::EU 2012Ontology Aware Applications @ YAPC::EU 2012
Ontology Aware Applications @ YAPC::EU 2012Nuno Carvalho
 
EclipseCon2008: The Dod, Open Source, and OSGi as Server Infrastructure
EclipseCon2008: The Dod, Open Source, and OSGi as Server InfrastructureEclipseCon2008: The Dod, Open Source, and OSGi as Server Infrastructure
EclipseCon2008: The Dod, Open Source, and OSGi as Server InfrastructureKit Plummer
 
Programming Languages and Software Construction
Programming Languages and Software ConstructionProgramming Languages and Software Construction
Programming Languages and Software ConstructionGneuromante canalada.org
 
Orion RESTful git API
Orion RESTful git APIOrion RESTful git API
Orion RESTful git APITomasz Zarna
 
The Whole Platform A Language Workbench for Eclipse
The Whole Platform A Language Workbench for EclipseThe Whole Platform A Language Workbench for Eclipse
The Whole Platform A Language Workbench for EclipseRiccardo Solmi
 
Openmokast: An open mobile broadcasting software stack for handheld devices
Openmokast: An open mobile broadcasting software stack for handheld devicesOpenmokast: An open mobile broadcasting software stack for handheld devices
Openmokast: An open mobile broadcasting software stack for handheld devicesJean-Michel Bouffard
 
Olpc France Presentation Erice 072008 Xavier Carcelle
Olpc France Presentation Erice 072008 Xavier CarcelleOlpc France Presentation Erice 072008 Xavier Carcelle
Olpc France Presentation Erice 072008 Xavier CarcelleDepend
 

Similar a Ada 95 - Programming in the large (20)

Developing Software that Matters II
Developing Software that Matters IIDeveloping Software that Matters II
Developing Software that Matters II
 
Ada 95 - Introduction
Ada 95 - IntroductionAda 95 - Introduction
Ada 95 - Introduction
 
Developing Software That Matters I
Developing Software That Matters IDeveloping Software That Matters I
Developing Software That Matters I
 
Ada 95 - Generics
Ada 95 - GenericsAda 95 - Generics
Ada 95 - Generics
 
Ada 95 - Structured programming
Ada 95 - Structured programmingAda 95 - Structured programming
Ada 95 - Structured programming
 
Keynote de Mike Milinkovich
Keynote de Mike MilinkovichKeynote de Mike Milinkovich
Keynote de Mike Milinkovich
 
OSS Legal issues method
OSS Legal issues methodOSS Legal issues method
OSS Legal issues method
 
Nokia and maemo in the new GNOME mobile context
 Nokia and maemo in the new GNOME mobile context Nokia and maemo in the new GNOME mobile context
Nokia and maemo in the new GNOME mobile context
 
I Diff 2008 conference IP-Racine Pictures
I Diff 2008 conference IP-Racine PicturesI Diff 2008 conference IP-Racine Pictures
I Diff 2008 conference IP-Racine Pictures
 
EOLE / OWF 12 - Viral licences – myth or reality - patrice-emmanuel schmitz (...
EOLE / OWF 12 - Viral licences – myth or reality - patrice-emmanuel schmitz (...EOLE / OWF 12 - Viral licences – myth or reality - patrice-emmanuel schmitz (...
EOLE / OWF 12 - Viral licences – myth or reality - patrice-emmanuel schmitz (...
 
What is new in Helios
What is new in HeliosWhat is new in Helios
What is new in Helios
 
"European Commission Open Source Observatory and Repository Project" by Ismae...
"European Commission Open Source Observatory and Repository Project" by Ismae..."European Commission Open Source Observatory and Repository Project" by Ismae...
"European Commission Open Source Observatory and Repository Project" by Ismae...
 
Ontology Aware Applications @ YAPC::EU 2012
Ontology Aware Applications @ YAPC::EU 2012Ontology Aware Applications @ YAPC::EU 2012
Ontology Aware Applications @ YAPC::EU 2012
 
EclipseCon2008: The Dod, Open Source, and OSGi as Server Infrastructure
EclipseCon2008: The Dod, Open Source, and OSGi as Server InfrastructureEclipseCon2008: The Dod, Open Source, and OSGi as Server Infrastructure
EclipseCon2008: The Dod, Open Source, and OSGi as Server Infrastructure
 
iText IP Review
iText IP ReviewiText IP Review
iText IP Review
 
Programming Languages and Software Construction
Programming Languages and Software ConstructionProgramming Languages and Software Construction
Programming Languages and Software Construction
 
Orion RESTful git API
Orion RESTful git APIOrion RESTful git API
Orion RESTful git API
 
The Whole Platform A Language Workbench for Eclipse
The Whole Platform A Language Workbench for EclipseThe Whole Platform A Language Workbench for Eclipse
The Whole Platform A Language Workbench for Eclipse
 
Openmokast: An open mobile broadcasting software stack for handheld devices
Openmokast: An open mobile broadcasting software stack for handheld devicesOpenmokast: An open mobile broadcasting software stack for handheld devices
Openmokast: An open mobile broadcasting software stack for handheld devices
 
Olpc France Presentation Erice 072008 Xavier Carcelle
Olpc France Presentation Erice 072008 Xavier CarcelleOlpc France Presentation Erice 072008 Xavier Carcelle
Olpc France Presentation Erice 072008 Xavier Carcelle
 

Más de Gneuromante canalada.org

Más de Gneuromante canalada.org (8)

Ast2Cfg - A Framework for CFG-Based Analysis and Visualisation of Ada Programs
Ast2Cfg - A Framework for CFG-Based Analysis and Visualisation of Ada ProgramsAst2Cfg - A Framework for CFG-Based Analysis and Visualisation of Ada Programs
Ast2Cfg - A Framework for CFG-Based Analysis and Visualisation of Ada Programs
 
SIGAda Hibachi Workshop Presentation
SIGAda Hibachi Workshop PresentationSIGAda Hibachi Workshop Presentation
SIGAda Hibachi Workshop Presentation
 
Developing Software that Matters (condensed)
Developing Software that Matters (condensed)Developing Software that Matters (condensed)
Developing Software that Matters (condensed)
 
Ada at Barco avionics
Ada at Barco avionicsAda at Barco avionics
Ada at Barco avionics
 
Ada 95 - Distributed systems
Ada 95 - Distributed systemsAda 95 - Distributed systems
Ada 95 - Distributed systems
 
Ada 95 - Object orientation
Ada 95 - Object orientationAda 95 - Object orientation
Ada 95 - Object orientation
 
Introduction to Ada
Introduction to AdaIntroduction to Ada
Introduction to Ada
 
Ada in Debian GNU/Linux
Ada in Debian GNU/LinuxAda in Debian GNU/Linux
Ada in Debian GNU/Linux
 

Último

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Último (20)

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Ada 95 - Programming in the large

  • 1. Franco Gasperoni gasperon@act-europe.fr http://libre.act-europe.fr 1 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 2. Copyright Notice • © ACT Europe under the GNU Free Documentation License • Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; provided its original author is mentioned and the link to http://libre.act-europe.fr/ is kept at the bottom of every non-title slide. A copy of the license is available at: • http://www.fsf.org/licenses/fdl.html 2 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 3. 3 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 4. What is the largest software system you have built ? (in SLOC) 4 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 5. Small Software Systems • Understandable by 1 person • Can throw away & replace it to – repair / extend – port to new platform • Anything is OK for small systems (< 10 Ksloc) 5 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 6. Medium/Large Systems • Team of people • No 1 person knows all its aspects • Long life-span (> 10 years) • CANNOT throw away & replace it to – repair / extend – port to new platform • Requires organization, discipline & right tools 6 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 7. • Programming in the Large – specification & implementation – privacy – abstract data types – hierarchical packages 7 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 8. Separate Compilation T C H O D Compiler object E E L C i P O D Compiler object n executable k R E e O r B L C O Compiler object E D E libraries M 8 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 9. Problem with this approach C C O C O O D D E D C E E O D C E O D E • No structure • To write your own code – YOU MUST understand everybody else’s code 9 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 10. Idea SPECIFY WHAT EACH MODULE SHOULD DO 10 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 11. SPECIFICATION ? BODY Software module 11 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 12. • Programming in the Large – specification & implementation • specification • implementation • specification rules in Ada 12 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 13. A Specification is a ... Users/clients Implementor of the of the module module CONTRACT • On the SERVICES provided by the module 13 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 14. • SPEC = list of services provided • BODY = implementation of the services (hidden) Service_1 Service_2 Service_3 Service_1 implementation Service_2 implementation Service_3 implementation Software module 14 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 15. SPECIFICATION ? BODY 15 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 16. Example • Create a Queue module that can – Add an Integer to the Queue – See the First integer in the Queue – Get the first integer in the Queue – Test whether the Queue is Empty 16 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 17. queue.ads queue.ads package Queue is package Queue is procedure Add (Element ::Integer); procedure Add (Element Integer); function First return Integer; function First return Integer; function Get return Integer; function Get return Integer; function Empty return Boolean; function Empty return Boolean; end Queue; end Queue; 17 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 18. queue.ads queue.ads package Queue is package Queue is procedure Add (Element : :Integer); procedure Add (Element Integer); function First return Integer; function First return Integer; function Get return Integer; function Get return Integer; function Empty return Boolean; function Empty return Boolean; end Queue; end Queue; ? BODY package Queue 18 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 19. Using package Queue client.adb with Queue; procedure Client is Queue_Error : exception; X : Integer; begin Queue.Add (3); Queue.Add (4); if not Queue.Empty then X := Queue.Get; else raise Queue_Error; end if; end Client; 19 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 20. Specifications Reduce Complexity SPEC SPEC SPEC SPEC SPEC SPEC SPEC SPEC • To write your own code – only need to understand specs for the services you need 20 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 21. To write Client only need to look at queue.ads queue.ads package Queue is package Queue is procedure Add (Element : :Integer); procedure Add (Element Integer); function First return Integer; function First return Integer; function Get return Integer; function Get return Integer; function Empty return Boolean; function Empty return Boolean; end Queue; end Queue; ? package Queue 21 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 22. Aside: use clause with Queue; use Queue; procedure Client is Queue_Error : exception; X : Integer; begin Queue. Add (3); Queue. Add (4); if not Queue. Empty then X := Queue. Get; else raise Queue_Error; end if; end Client; 22 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 23. • Programming in the Large – specification & implementation • specification • implementation • specification rules in Ada 23 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 24. ONE possible implementation of package Queue This implementation raises Constraint_Error if more than Max_Size elements are put in the Queue. 24 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 25. Circular Buffer Q 0 1 Max_Size - 1 Q_Last Q_First 25 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 26. queue.adb package body Queue is Max_Size : constant := 100; type Q_Index is mod Max_Size; Q : array (Q_Index range 0 .. Max_Size - 1) of Integer; Q_First : Q_Index := Q ’ First; Q_Last : Q_Index := Q_First; Size : Natural range 0 .. Max_Size; procedure Add (Element : Integer) is begin Q (Q_Last) := Element; Q_Last := Q_Last + 1; Size := Size + 1; end Add; ... 26 end Queue; http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 27. package body Queue is queue.adb ... function First return Integer is begin return Q (Q_First); end First; function Get return Integer is begin Q_First := Q_First + 1; Size := Size - 1; return Q (Q_First - 1); end Get; function Empty return Boolean is begin return Size = 0; end Empty; 27 http://libre.act-europe.fr end Queue; under the GNU Free Documentation License © ACT Europe
  • 28. ANOTHER possible implementation of package Queue 28 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 29. Linked List Q_First Q_Last Free 29 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 30. queue.adb package body Queue is type Queue_Element; type Element_Ptr is access Queue_Element; type Queue_Element is record Val : Integer; Next : Element_Ptr; end record; Q_First : Element_Ptr; Q_Last : Element_Ptr; Free : Element_Ptr := new Queue_Element; ... end Queue; 30 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 31. queue.adb package body Queue is ... procedure Add (Element : Integer) is begin if Q_First = null then Q_First := Free; else Q_Last.Next := Free; end if; Q_Last := Free; Free := Free.Next; Q_Last.all := (Element, null); if Free = null then Free := new Queue_Element; end if; end Add; ... 31 end Queue; http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 32. queue.adb package body Queue is ... function Get return Integer is Tmp : Element_Ptr := Q_First; begin Q_First := Q_First.Next; if Q_First = null then Q_Last := null; end if; Tmp.Next := Free; Free := Tmp; return Tmp.Val; end Get; ... end Queue; 32 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 33. queue.adb package body Queue is ... function First return Integer is begin return Q_First; end First; function Empty return Boolean is begin return Q_First = null; end Empty; end Queue; 33 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 34. A Spec can have several implementations queue.ads queue.ads package Queue is package Queue is (Element : Integer); procedure Add procedure Add (Element : Integer); function First return Integer; function First return Integer; function Get return Integer; function Get return Integer; function Empty return Boolean; function Empty return Boolean; end Queue; end Queue; • Can change implementation second second first first implement. implement. implement. implement. • WITHOUT having to change ANY of the client’s code 34 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 35. • Programming in the Large – specification & implementation • specification • implementation • specification rules in Ada 35 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 36. In Ada • Spec always checked against implementation • Must with the specs that you are going to use (not in C) • Packages provide multiple name spaces 36 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 37. Spec is checked against its body package Queue is package Queue is procedure Add (Element ::Integer); procedure Add (Element Integer); ... ... end Queue; end Queue; Compilation error package body Queue is package body Queue is ... ... procedure Add (Element ::Integer; X ::Float) is procedure Add (Element Integer; X Float) is ... ... end Add; end Add; ... ... end Queue; end Queue; 37 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 38. Must with Specs used with Queue; procedure Client is Compilation ... error begin Queue.Add (3); ... end Client; 38 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 39. Multiple Name Spaces package Queue is package Queue is package Set is package Set is procedure Add (E ::Integer); procedure Add (E Integer); procedure Add (E ::Integer); procedure Add (E Integer); ... ... ... ... end Queue; end Queue; end Set; end Set; with Queue; with Set; procedure Client is begin Queue.Add (3); Set.Add (99); end Client; 39 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 40. Use Clause and Ambiguities package Queue is package Queue is package Set is package Set is procedure Add (E ::Integer); procedure Add (E Integer); procedure Add (E ::Integer); procedure Add (E Integer); ... ... ... ... end Queue; end Queue; end Set; end Set; with Queue; use Queue; with Set; use Set; procedure Client is begin Compilation Add (123); error end Client; ambiguity 40 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 41. But … Ada has overloading package Queue is package Queue is procedure Add (E ::Integer); procedure Add (E Integer); procedure Add (E ::Float); procedure Add (E Float); ... ... end Queue; end Queue; with Queue; use Queue; procedure Client is begin Add (123); Add (3.141); end Client; 41 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 42. • Programming in the Large – specification & implementation – privacy – abstract data types – hierarchical packages 42 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 43. Having Several Queues package Queues is package Queues is type Queue is …; type Queue is …; procedure Add (Q ::Queue; Element ::Integer); procedure Add (Q Queue; Element Integer); function First (Q ::Queue) return Integer; function First (Q Queue) return Integer; function Get (Q :: Queue) return Integer; function Get (Q Queue) return Integer; function Empty (Q ::Queue) return Boolean; function Empty (Q Queue) return Boolean; end Queues; end Queues; 43 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 44. !!! WARNING !!! package Queues is package Queues is type Queue is …; Use Different names type Queue is …; end Queues; end Queues; 44 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 45. Using Several Queues with Queues; use Queues; procedure Client is Q1 : Queue; Q2 : Queue; begin Add (Q1, 123); Add (Q2, 3); Add (Q2, Get (Q1)); end Client; 45 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 46. One possible implementation ... type Q_Element; type Q_Element; type Element_Ptr is type Element_Ptr is access Queue_Element; access Queue_Element; type Queue_Element is record type Queue_Element is record Val ::Integer; Val Integer; Next ::Element_Ptr; Next Element_Ptr; end record; end record; package Queues is type Queue is …; type Queue is record type Queue is record First ::Element_Ptr; First Element_Ptr; procedure Add (Q : Queue; Element : Integer); Last : Element_Ptr; function First (Q : Queue) return Integer; Last : Element_Ptr; end record; function Get (Q : Queue) return Integer; end record; function Empty (Q : Queue) return Boolean; end Queues; 46 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 47. Client code allowed to depend on the implementation ! with Queues; use Queues; procedure Client is Q1 : Queue; Q2 : Queue; begin Add (Q1, 123); Add (Q2, 3); Q2.Last := null; OK end Client; 47 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 48. Another implementation ... Max_Size ::constant := 100; Max_Size constant := 100; type Q_array (Natural range <>) type Q_array (Natural range <>) of Integer; of Integer; type Queue is record type Queue is record Q ::Q_Array (0 .. Max_Size); Q Q_Array (0 .. Max_Size); package Queues is First ::Natural; First Natural; type Queue is …; Last ::Natural; Last Natural; procedure Add (Q : Queue; Element : Integer);Size ::Natural; Size Natural; end record; function First (Q : Queue) return Integer;end record; function Get (Q : Queue) return Integer; function Empty (Q : Queue) return Boolean; end Queues; 48 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 49. … breaks client code ! with Queues; use Queues; procedure Client is Q1 : Queue; Q2 : Queue; begin Add (Q1, 123); Add (Q2, 3); Compilation error Q2.Last := null; end Client; 49 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 50. Even without changing the implementation there is a PROBLEM with Queues; use Queues; procedure Client is Q1 : Queue; Q2 : Queue; begin Add (Q1, 123); Q2: Q2 is in an 3 3 inconsistent Add (Q2, 3); First state Last Q2.Last := null; end Client; null 50 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 51. You need PRIVACY • Exposing your data structures is risky – Client code may manipulate the structures directly without using your own services – Client code is hard to change 51 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 52. Think BIG what if the Queues package is used by 1000s of other packages 52 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 53. • If there is a bug concerning a Queue, you may have to look at 1000s of packages to find the bug • If you change the implementation you may have to update 1000s of packages 53 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 54. • Programming in the Large – privacy • private types • private types & discriminants • limited private types 54 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 55. Private types package Queues is package Queues is type Queue is private; type Queue is private; procedure Add (Q ::Queue; Element ::Integer); procedure Add (Q Queue; Element Integer); function First (Q ::Queue) return Integer; function First (Q Queue) return Integer; function Get (Q :: Queue) return Integer; function Get (Q Queue) return Integer; function Empty (Q ::Queue) return Boolean; function Empty (Q Queue) return Boolean; private private type Queue is …; type Queue is …; end Queues; end Queues; 55 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 56. In any implementation ... package Queues is type Queue is private; procedure Add (Q : Queue; Element : Integer); function First (Q : Queue) return Integer; function Get (Q : Queue) return Integer; function Empty (Q : Queue) return Boolean; private type Queue_Element; type Element_Ptr is access Queue_Element; type Queue_Element is record Val : Integer; Next : Element_Ptr; end record; type Queue is record First : Element_Ptr; Last : Element_Ptr; end record; end Queues; 56 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 57. … private types are PRIVATE with Queues; use Queues; procedure Client is Q1 : Queue; Q2 : Queue; begin Add (Q1, 123); Add (Q2, 3); Compilation Q2.Last := null; error end Client; 57 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 58. Advantages of private types • Enforces the contract of a specification • No client code can corrupt your data structures • Can change implementation without changing client code 58 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 59. Why is the private part in the spec ? package Queues is type Queue is private; procedure Add (Q : Queue; Element : Integer); function First (Q : Queue) return Integer; function Get (Q : Queue) return Integer; function Empty (Q : Queue) return Boolean; private type Queue_Element; type Element_Ptr is access Queue_Element; type Queue_Element is record Val : Integer; Next : Element_Ptr; end record; type Queue is record First : Element_Ptr; Last : Element_Ptr; end record; end Queues; © ACT Europe under the GNU Free Documentation License 59 http://libre.act-europe.fr
  • 60. … because we still need to compile the clients code with Queues; use Queues; procedure Client is Q1 : Queue; begin Add (Q1, 123); end Client; 60 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 61. … but you can make a private type quite private package Queues is type Queue is private; procedure Add (Q : Queue; Element : Integer); function First (Q : Queue) return Integer; function Get (Q : Queue) return Integer; function Empty (Q : Queue) return Boolean; private type Queue_Info; type Queue is access Queue_Info; end Queues; 61 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 62. package body Queues is type Queue_Element; type Element_Ptr is access Queue_Element; type Queue_Element is record Val : Integer; Next : Element_Ptr; end record; type Queue_Info is record First : Element_Ptr; Last : Element_Ptr; end record; ... end Queues; 62 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 63. • Programming in the Large – privacy • private types • private types & discriminants • limited private types 63 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 64. package Queues is type Queue (Max_Size : Natural) is private; procedure Add (Q : Queue; Element : Integer); function First (Q : Queue) return Integer; function Get (Q : Queue) return Integer; function Empty (Q : Queue) return Boolean; private type Q_array (Natural range <>) of Integer; type Queue (Max_Size : Natural) is record Q : Q_Array (0 .. Max_Size); First : Natural; Last : Natural; Size : Natural; end record; end Queues; 64 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 65. with Queues; use Queues; procedure Client is Q1 : Queue (100); Q1 can have up to 100 elmts Q2 : Queue (250); Q2 can have up to 250 elmts begin Add (Q1, 123); Add (Q2, 3); end Client; 65 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 66. • Programming in the Large – privacy • private types • private types & discriminants • limited private types 66 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 67. with Queues; use Queues; procedure Client is Q1 : Queue; Q2 : Queue; X : Integer; begin Add (Q1, 123); Add (Q1, 3); Does this affect Q1 ? Q2 := Q1; X := Get (Q2); end Client; 67 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 68. it depends on … the implementation ! • If a Queue is implemented with – a pointer then Get (Q2) MODIFIES Q1 – a record containing an array then Get (Q2) does NOT modify Q1 68 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 69. with Queues; use Queues; Pointer procedure Client is Pointer Q1 : Queue; implementation implementation Q2 : Queue; X : Integer; begin Q1: 123 123 Add (Q1, 123); Add (Q1, 3); 123 3 Q1: 123 3 Q2 := Q1; Q2: Q1: 123 123 3 3 X := Get (Q2); end Client; Q2: 69 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 70. limited private types • NO assignment := • NO equality comparison = 70 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 71. package Queues is package Queues is type Queue is limited private; type Queue is limited private; procedure Add (Q ::Queue; Element ::Integer); procedure Add (Q Queue; Element Integer); function First (Q ::Queue) return Integer; function First (Q Queue) return Integer; function Get (Q :: Queue) return Integer; function Get (Q Queue) return Integer; function Empty (Q ::Queue) return Boolean; function Empty (Q Queue) return Boolean; private private type Queue is …; type Queue is …; end Queues; end Queues; 71 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 72. with Queues; use Queues; procedure Client is Q1 : Queue; Q2 : Queue; X : Integer; begin Add (Q1, 123); Add (Q1, 3); COMPILATION ERROR Q2 := Q1; := forbidden end Client; 72 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 73. • Programming in the Large – specification & implementation – privacy – abstract data types – hierarchical packages 73 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 74. Queue is an Abstract Data Type (ADT) • Set of abstract values (data domain) ADT = • collection of abstract Operations (routines that manipulate the values) 74 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 75. Queue is an ADT values package Queues is package Queues is type Queue is limited private; type Queue is limited private; procedure Add (Q ::Queue; Element ::Integer); procedure Add (Q Queue; Element Integer); function First (Q ::Queue) return Integer; function First (Q Queue) return Integer; function Get (Q :: Queue) return Integer; function Get (Q Queue) return Integer; function Empty (Q ::Queue) return Boolean; function Empty (Q Queue) return Boolean; private private type Queue is …; type Queue is …; operations end Queues; end Queues; 75 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 76. Objects & Variables • OBJECT = instance of an ADT – piece of memory containing values of the ADT • VARIABLE = name of a specific object • not all objects have a name 76 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 77. an object My_Q : Queue; Queue object name of the object Memory 77 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 78. not all objects have a name type Queue_Ptr is access Queue; Queue object Ptr : Queue_Ptr; Ptr := new Queue; object has no name Ptr is just a pointer to the object Memory 78 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 79. CLASS = ADT + inheritance 79 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 80. operation invoke some operation in the SPEC operation to use ADT services operation Private data ENCAPSULATION 80 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 81. The object model 81 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 82. The C model GLOBAL DATA C module C module C module 82 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 83. • Programming in the Large – specification & implementation – privacy – abstract data types – hierarchical packages 83 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 84. To add functionality ... function Last (Q : Queue) return Integer; package Queues is type Queue is private; procedure Add (Q : Queue; Element : Integer); function First (Q : Queue) return Integer; function Get (Q : Queue) return Integer; function Empty (Q : Queue) return Boolean; function Last (Q : Queue) return Integer; private type Queue is …; Must add end Queues; it to Queues Queue is a private type 84 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 85. But ... • Every time you change a spec you must recompile all its clients • Every time you change a module you must RETEST the whole module 85 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 86. Solution: use child units queues.ads package Queues is type Queue is private; procedure Add (Q : Queue; Element : Integer); function First (Q : Queue) return Integer; function Get (Q : Queue) return Integer; function Empty (Q : Queue) return Boolean; private type Queue is …; Child end Queues; subprogram queues-last.ads function Queues . Last (Q : Queue) return Integer; 86 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 87. Child Units Rules • The body or private part of a child unit can see the private part of all of its parents • The spec of a child unit does NOT 87 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 88. Using a child unit with Queues; use Queues; with Queues.Last; procedure Client is Q : Queue; X : Integer; begin Add (Q, 123); Add (Q, 3); X := Queues.Last (Q); end Client; 88 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 89. queues.ads package Queues is type Queue is private; procedure Add (Q : Queue; Element : Integer); function First (Q : Queue) return Integer; function Get (Q : Queue) return Integer; function Empty (Q : Queue) return Boolean; private type Queue is …; end Queues; Child package queues-new_functionality.ads package Queues . New_Functionality is function Last (Q : Queue) return Integer; end Queues . New_Functionality 89 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 90. with Queues; use Queues; with Queues.New_Functionality; procedure Client is Q : Queue; X : Integer; begin Add (Q, 123); Add (Q, 3); X := Queues.New_Functionality.Last (Q); end Client; 90 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License