SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
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
When creating a new system
                 you must identify its ...


             • Data types
                             (what kind of data will be manipulated)


             • Functionalities
                             (what kind of manipulations are allowed)


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


        • Around its functionalities
             (structured programming)

        • around its data types
             (object-oriented programming)



                                                                                     5
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
• Functionality-Oriented Org.

                             – variant programming
                             – modifying functionality-oriented sys.
                             – when to use functionality-oriented




                                                                                             6
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
Design an alert system
                             for an industrial plant

           • log all the incoming alerts

           • handle an alert (inform right people, etc.)




                                                                                           7
http://libre.act-europe.fr         © ACT Europe under the GNU Free Documentation License
alerts.ads
                                                                                              alerts.ads
                        with Calendar;
                        with Calendar;

                        package Alerts is
                        package Alerts is
                            type Alert is private;
                           type Alert is private;

                             procedure Handle (A ::in out Alert);
                             procedure Handle (A in out Alert);
                             procedure Log (A :: Alert);
                                              (A Alert);
                             procedure Log

                         private
                         private
                             type Alert is record
                            type Alert is record
                               Time_Of_Arrival ::Calendar.Time;
                                Time_Of_Arrival Calendar.Time;
                                Cause            ::String (1 .. 200);
                                                   String (1 .. 200);
                               Cause
                             end record;
                            end record;
                        end Alerts;
                        end Alerts;
                                                                                                           8
http://libre.act-europe.fr            © ACT Europe under the GNU Free Documentation License
Having several kind of alerts
      • Low

      • Medium
             – dispatch a technician


      • High
             – dispatch an engineer
             – if problem not fixed within a delay ring an alarm




                                                                                       9
http://libre.act-europe.fr     © ACT Europe under the GNU Free Documentation License
with Calendar; use Calendar;
     with Persons; use Persons;

     package Alerts is
        type Priority is (Low, Medium, High);
        type Alert (P : Priority) is private;

            procedure Handle            (A : in out Alert);
            procedure Log               (A : Alert);

            procedure Set_Alarm (A : in out Alert; Wait : Duration);

     private
         type Alert (P : Priority) is record ... end record;
     end Alerts;

                                                                                      10
http://libre.act-europe.fr    © ACT Europe under the GNU Free Documentation License
discriminant
                             private
                                 type Alert (P : Priority) is record
                                    Time_Of_Arrival : Time;
                                    Cause             : String (1 .. 100);

                                         case P is
                                            when Low                        =>
                                                 null;
            variant
            record                               when Medium =>
                                                   Technician : Person;

                                        when High                            =>
                                                Engineer                                      : Person;
                                                Ring_Alarm_At : Time;
                                   end case;
                                end record;                                                               11
                             end Alerts; © ACT Europe under the GNU Free Documentation License
http://libre.act-europe.fr
• Functionality-Oriented Org.

                             – variant programming
                             – modifying functionality-oriented sys.
                             – when to use functionality-oriented




                                                                                             12
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
Variant Programming
         procedure Handle (A : in out Alert) is
         begin
            A.Time_Of_Arrival := Calendar.Clock;
            A.Cause           := Get_Cause (A);
            Log (A);
            case A.P is
               when Low     =>
                  null;
                        when Medium =>
                          A.Technician := Assign_Technician;
              when High     =>
                 A.Engineer := Assign_Engineer;
                 Set_Alarm (A, Wait => 1800);
              end case;
                                                                                            13
         end Handle;
http://libre.act-europe.fr          © ACT Europe under the GNU Free Documentation License
Typical Routine for Alert Objects
                 (version 1)
           procedure Some_Routine (A : in out Alert) is
           begin
                 ...
             case A.P is
                when Low     =>
                   ...
                 when Medium =>
                   ...
                 when High   =>
                   ...
                 end case;
           end Some_Routine;
                                                                                     14
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
Typical Routine for Alert Objects
                 (version 2)
           procedure Some_Routine (A : in out Alert) is
           begin
                 ...
             if A.P = Low then
                     ...
             elsif A.P = Medium then
                     ...
             elsif A.P = High then
                     ...
             else
                 raise Internal_Error; -- defensive programming
             end if;
           end Some_Routine;                                                          15
http://libre.act-europe.fr    © ACT Europe under the GNU Free Documentation License
Variant Programming is checked

        procedure Set_Alarm (A : in out Alert; Wait : Duration) is
        begin
           A.Ring_Alarm_At := A.Time_Of_Arrival + Wait;
        end Handle;


                                                 Constraint_Error

                                                            raised if
                                                A.Priority /= High

                                                                                     16
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
Handling an Alert

           • You have a Get_Alert routine
           • Connected to the sensors in the factory
           • Collects the alerts
          with Alerts; use Alerts;
         with Alerts; use Alerts;
          function Get_Alert return Alert;                                    Returns an
         function Get_Alert return Alert;
                                                                          unconstrained Alert
                                                                        the discriminant value
                                                                             is not known
                                                                            at compile time
                                                                                             17
http://libre.act-europe.fr      © ACT Europe under the GNU Free Documentation License
with Alerts; use Alerts;
     with Alerts; use Alerts;
     with Get_Alert;
     with Get_Alert;
     procedure Process_Alerts is
     procedure Process_Alerts is
     begin
     begin
                                             Probably a
         loop -- infinite loop
        loop -- infinite loop
                                            blocking call
            declare
           declare
              A ::Alert := Get_Alert;
               A Alert := Get_Alert;
            begin
           begin
              Handle (A); -- could have written Handle (Get_Alert);
              Handle (A); -- could have written Handle (Get_Alert);
            end;
           end;
         end loop;
        end loop;
     end Process_Alerts;
     end Process_Alerts;

         • The case inside Handle selects the right to
           execute depending on the discriminant
         • Handling code centralized in Handle                                       18
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
• Functionality-Oriented Org.

                             – variant programming
                             – modifying functionality-oriented sys.
                             – when to use functionality-oriented




                                                                                             19
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
Adding NEW Functionality...

           • Do not modify what is working already
                  – No need to retest what you already did
                    since you do not need to touch it


           • Just add the functionality in a separate
             child unit (subprogram or package)


                                                                                       20
http://libre.act-europe.fr     © ACT Europe under the GNU Free Documentation License
Adding new functionality
           It’s simple: Use child subprograms/packages
                simple

           procedure Alerts.New_Functionality (A : in out Alert) is
           begin
                 ...
             case A.P is
                when Low     =>
                     ...
                 when Medium =>
                     ...
                 when High    =>
                     ...
              end case;
           end Alerts.New_Functionality;                                              21
http://libre.act-europe.fr    © ACT Europe under the GNU Free Documentation License
Adding a NEW Data Variant...
           • You have to modify the spec containing
             your data type

           • have to modify all the routines that
             manipulate the data type to process new
             variant
                  – Error Prone & labor intensive
                  – need to retest everything for regressions

                                                                                       22
http://libre.act-europe.fr     © ACT Europe under the GNU Free Documentation License
Adding a data type
           Much more work: need to modify the spec...
                     work
                             package Alerts is
                                 ...
                             private
                                 type Alert (P : Priority) is record
                                    ...
                                     case P is
                                         when Low        => . . .
                                         when Medium => . . .
                                         when High       => . . .
                                         when Emergency => . . .
                                     end case;
                                 end record;
                             end Alerts;                                                      23
http://libre.act-europe.fr            © ACT Europe under the GNU Free Documentation License
… as well as ALL the routines using Alert
           procedure Some_Routine (A : in out Alert) is
           begin
                 ...
             case A.P is
                when Low     =>
                   ...
                 when Medium =>
                   ...
                 when High   =>
                   ...
                 when Emergency =>
                   ...
                 end case;
           end Some_Routine;                                                         24
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License
... ALL the routines !
           procedure Some_Routine (A : in out Alert) is
           begin
                 ...
             if A.P = Low then
                     ...
             elsif A.P = Medium then
                     ...
             elsif A.P = High then
                     ...
             elsif A.P = Emergency then
                     ...
             else
                 raise Internal_Error; -- defensive programming
             end if;
           end Some_Routine;
                                                                                      25
http://libre.act-europe.fr    © ACT Europe under the GNU Free Documentation License
Important Remark

        • For either type of change client routines such as
          Process_Alerts do not need modifications

                       with Alerts; use Alerts;
                       with Alerts; use Alerts;
                       with Get_Alert;
                       with Get_Alert;
                       procedure Process_Alerts is
                       procedure Process_Alerts is
                       begin
                       begin
                           loop -- infinite loop
                          loop -- infinite loop
                              Handle (Get_Alert);
                             Handle (Get_Alert);
                           end loop;
                          end loop;
                       end Process_Alerts;
                       end Process_Alerts;                                                 26
http://libre.act-europe.fr         © ACT Europe under the GNU Free Documentation License
• Functionality-Oriented Org.

                             – variant programming
                             – modifying functionality-oriented sys.
                             – when to use functionality-oriented




                                                                                             27
http://libre.act-europe.fr           © ACT Europe under the GNU Free Documentation License
• Data types are well known before
       starting the design

     • Adding new data variants will happen
       infrequently


     • Will add lots of new functionalities on
       existing data types over the life time of
       the system
                                                                                     28
http://libre.act-europe.fr   © ACT Europe under the GNU Free Documentation License

Mais conteúdo relacionado

Destaque

FINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEMFINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEM
Amira Dolce Farhana
 
Csc1100 lecture01 ch01 pt2-paradigm
Csc1100 lecture01 ch01 pt2-paradigmCsc1100 lecture01 ch01 pt2-paradigm
Csc1100 lecture01 ch01 pt2-paradigm
IIUM
 
Database Management System And Design Questions
Database Management System And Design QuestionsDatabase Management System And Design Questions
Database Management System And Design Questions
Samir Sabry
 
2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper
Monica Sabharwal
 
Programming Languages and Program Develompent
Programming Languages and Program DevelompentProgramming Languages and Program Develompent
Programming Languages and Program Develompent
Samudin Kassan
 

Destaque (20)

FINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEMFINAL PAPER FP304 DATABASE SYSTEM
FINAL PAPER FP304 DATABASE SYSTEM
 
Uses of Cupcakes For Any Occasion in Hyderabad!
 Uses of Cupcakes For Any Occasion in Hyderabad! Uses of Cupcakes For Any Occasion in Hyderabad!
Uses of Cupcakes For Any Occasion in Hyderabad!
 
Csc1100 lecture01 ch01 pt2-paradigm
Csc1100 lecture01 ch01 pt2-paradigmCsc1100 lecture01 ch01 pt2-paradigm
Csc1100 lecture01 ch01 pt2-paradigm
 
Core FP Concepts
Core FP ConceptsCore FP Concepts
Core FP Concepts
 
Oop project briefing sem 1 2015 2016
Oop project briefing  sem 1 2015 2016Oop project briefing  sem 1 2015 2016
Oop project briefing sem 1 2015 2016
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Database Management System And Design Questions
Database Management System And Design QuestionsDatabase Management System And Design Questions
Database Management System And Design Questions
 
2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper2009 Punjab Technical University B.C.A Database Management System Question paper
2009 Punjab Technical University B.C.A Database Management System Question paper
 
Functional programming principles and Java 8
Functional programming principles and Java 8Functional programming principles and Java 8
Functional programming principles and Java 8
 
Understanding Computers: Today and Tomorrow, 13th Edition Chapter 13 - Progra...
Understanding Computers: Today and Tomorrow, 13th Edition Chapter 13 - Progra...Understanding Computers: Today and Tomorrow, 13th Edition Chapter 13 - Progra...
Understanding Computers: Today and Tomorrow, 13th Edition Chapter 13 - Progra...
 
Dbms Final Examination Answer Key
Dbms Final Examination Answer KeyDbms Final Examination Answer Key
Dbms Final Examination Answer Key
 
Mcs 16 solved assignment 2015-16
Mcs 16 solved assignment 2015-16Mcs 16 solved assignment 2015-16
Mcs 16 solved assignment 2015-16
 
Functional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for MaintainabilityFunctional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for Maintainability
 
Good Programming Practice
Good Programming PracticeGood Programming Practice
Good Programming Practice
 
Why C is Called Structured Programming Language
Why C is Called Structured Programming LanguageWhy C is Called Structured Programming Language
Why C is Called Structured Programming Language
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Programming Languages and Program Develompent
Programming Languages and Program DevelompentProgramming Languages and Program Develompent
Programming Languages and Program Develompent
 
Functional programming in java
Functional programming in javaFunctional programming in java
Functional programming in java
 
Principles Of Programing Languages
Principles Of Programing LanguagesPrinciples Of Programing Languages
Principles Of Programing Languages
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
 

Semelhante a Ada 95 - Structured programming

Hack.lu 09 ip-morph
Hack.lu 09 ip-morphHack.lu 09 ip-morph
Hack.lu 09 ip-morph
Steph Cliche
 

Semelhante a Ada 95 - Structured programming (9)

Ada 95 - Object orientation
Ada 95 - Object orientationAda 95 - Object orientation
Ada 95 - Object orientation
 
Ada 95 - Generics
Ada 95 - GenericsAda 95 - Generics
Ada 95 - Generics
 
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
 
Ada 95 - Programming in the large
Ada 95 - Programming in the largeAda 95 - Programming in the large
Ada 95 - Programming in the large
 
"Understanding Free Software and Open Source Licensing" by Zak Greant @ eLibe...
"Understanding Free Software and Open Source Licensing" by Zak Greant @ eLibe..."Understanding Free Software and Open Source Licensing" by Zak Greant @ eLibe...
"Understanding Free Software and Open Source Licensing" by Zak Greant @ eLibe...
 
OSS Legal issues method
OSS Legal issues methodOSS Legal issues method
OSS Legal issues method
 
Hack.lu 09 ip-morph
Hack.lu 09 ip-morphHack.lu 09 ip-morph
Hack.lu 09 ip-morph
 
App armor structure
App armor structureApp armor structure
App armor structure
 

Mais de Gneuromante canalada.org

Mais de Gneuromante canalada.org (9)

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
 
Programming Languages and Software Construction
Programming Languages and Software ConstructionProgramming Languages and Software Construction
Programming Languages and Software Construction
 
Ada 95 - Distributed systems
Ada 95 - Distributed systemsAda 95 - Distributed systems
Ada 95 - Distributed systems
 
Developing Software That Matters I
Developing Software That Matters IDeveloping Software That Matters I
Developing Software That Matters I
 
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

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Ada 95 - Structured programming

  • 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. When creating a new system you must identify its ... • Data types (what kind of data will be manipulated) • Functionalities (what kind of manipulations are allowed) 4 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 5. Software System Organization • Around its functionalities (structured programming) • around its data types (object-oriented programming) 5 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 6. • Functionality-Oriented Org. – variant programming – modifying functionality-oriented sys. – when to use functionality-oriented 6 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 7. Design an alert system for an industrial plant • log all the incoming alerts • handle an alert (inform right people, etc.) 7 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 8. alerts.ads alerts.ads with Calendar; with Calendar; package Alerts is package Alerts is type Alert is private; type Alert is private; procedure Handle (A ::in out Alert); procedure Handle (A in out Alert); procedure Log (A :: Alert); (A Alert); procedure Log private private type Alert is record type Alert is record Time_Of_Arrival ::Calendar.Time; Time_Of_Arrival Calendar.Time; Cause ::String (1 .. 200); String (1 .. 200); Cause end record; end record; end Alerts; end Alerts; 8 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 9. Having several kind of alerts • Low • Medium – dispatch a technician • High – dispatch an engineer – if problem not fixed within a delay ring an alarm 9 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 10. with Calendar; use Calendar; with Persons; use Persons; package Alerts is type Priority is (Low, Medium, High); type Alert (P : Priority) is private; procedure Handle (A : in out Alert); procedure Log (A : Alert); procedure Set_Alarm (A : in out Alert; Wait : Duration); private type Alert (P : Priority) is record ... end record; end Alerts; 10 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 11. discriminant private type Alert (P : Priority) is record Time_Of_Arrival : Time; Cause : String (1 .. 100); case P is when Low => null; variant record when Medium => Technician : Person; when High => Engineer : Person; Ring_Alarm_At : Time; end case; end record; 11 end Alerts; © ACT Europe under the GNU Free Documentation License http://libre.act-europe.fr
  • 12. • Functionality-Oriented Org. – variant programming – modifying functionality-oriented sys. – when to use functionality-oriented 12 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 13. Variant Programming procedure Handle (A : in out Alert) is begin A.Time_Of_Arrival := Calendar.Clock; A.Cause := Get_Cause (A); Log (A); case A.P is when Low => null; when Medium => A.Technician := Assign_Technician; when High => A.Engineer := Assign_Engineer; Set_Alarm (A, Wait => 1800); end case; 13 end Handle; http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 14. Typical Routine for Alert Objects (version 1) procedure Some_Routine (A : in out Alert) is begin ... case A.P is when Low => ... when Medium => ... when High => ... end case; end Some_Routine; 14 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 15. Typical Routine for Alert Objects (version 2) procedure Some_Routine (A : in out Alert) is begin ... if A.P = Low then ... elsif A.P = Medium then ... elsif A.P = High then ... else raise Internal_Error; -- defensive programming end if; end Some_Routine; 15 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 16. Variant Programming is checked procedure Set_Alarm (A : in out Alert; Wait : Duration) is begin A.Ring_Alarm_At := A.Time_Of_Arrival + Wait; end Handle; Constraint_Error raised if A.Priority /= High 16 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 17. Handling an Alert • You have a Get_Alert routine • Connected to the sensors in the factory • Collects the alerts with Alerts; use Alerts; with Alerts; use Alerts; function Get_Alert return Alert; Returns an function Get_Alert return Alert; unconstrained Alert the discriminant value is not known at compile time 17 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 18. with Alerts; use Alerts; with Alerts; use Alerts; with Get_Alert; with Get_Alert; procedure Process_Alerts is procedure Process_Alerts is begin begin Probably a loop -- infinite loop loop -- infinite loop blocking call declare declare A ::Alert := Get_Alert; A Alert := Get_Alert; begin begin Handle (A); -- could have written Handle (Get_Alert); Handle (A); -- could have written Handle (Get_Alert); end; end; end loop; end loop; end Process_Alerts; end Process_Alerts; • The case inside Handle selects the right to execute depending on the discriminant • Handling code centralized in Handle 18 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 19. • Functionality-Oriented Org. – variant programming – modifying functionality-oriented sys. – when to use functionality-oriented 19 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 20. Adding NEW Functionality... • Do not modify what is working already – No need to retest what you already did since you do not need to touch it • Just add the functionality in a separate child unit (subprogram or package) 20 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 21. Adding new functionality It’s simple: Use child subprograms/packages simple procedure Alerts.New_Functionality (A : in out Alert) is begin ... case A.P is when Low => ... when Medium => ... when High => ... end case; end Alerts.New_Functionality; 21 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 22. Adding a NEW Data Variant... • You have to modify the spec containing your data type • have to modify all the routines that manipulate the data type to process new variant – Error Prone & labor intensive – need to retest everything for regressions 22 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 23. Adding a data type Much more work: need to modify the spec... work package Alerts is ... private type Alert (P : Priority) is record ... case P is when Low => . . . when Medium => . . . when High => . . . when Emergency => . . . end case; end record; end Alerts; 23 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 24. … as well as ALL the routines using Alert procedure Some_Routine (A : in out Alert) is begin ... case A.P is when Low => ... when Medium => ... when High => ... when Emergency => ... end case; end Some_Routine; 24 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 25. ... ALL the routines ! procedure Some_Routine (A : in out Alert) is begin ... if A.P = Low then ... elsif A.P = Medium then ... elsif A.P = High then ... elsif A.P = Emergency then ... else raise Internal_Error; -- defensive programming end if; end Some_Routine; 25 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 26. Important Remark • For either type of change client routines such as Process_Alerts do not need modifications with Alerts; use Alerts; with Alerts; use Alerts; with Get_Alert; with Get_Alert; procedure Process_Alerts is procedure Process_Alerts is begin begin loop -- infinite loop loop -- infinite loop Handle (Get_Alert); Handle (Get_Alert); end loop; end loop; end Process_Alerts; end Process_Alerts; 26 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 27. • Functionality-Oriented Org. – variant programming – modifying functionality-oriented sys. – when to use functionality-oriented 27 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
  • 28. • Data types are well known before starting the design • Adding new data variants will happen infrequently • Will add lots of new functionalities on existing data types over the life time of the system 28 http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License