Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 © AdaCore under the GNU Free Documentation License Franco Gasperoni

Similar presentations


Presentation on theme: "1 © AdaCore under the GNU Free Documentation License Franco Gasperoni"— Presentation transcript:

1 1 http://libre.adacore.com © AdaCore under the GNU Free Documentation License Franco Gasperoni gasperoni@adacore.com http://libre.adacore.com

2 2 © AdaCore 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

3 3 http://libre.adacore.com © AdaCore under the GNU Free Documentation License

4 4 http://libre.adacore.com © AdaCore 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)

5 5 http://libre.adacore.com © AdaCore under the GNU Free Documentation License Software System Organization Around its functionalities (structured programming) around its data types (object-oriented programming)

6 6 http://libre.adacore.com © AdaCore under the GNU Free Documentation License Functionality-Oriented Org. –variant programming –modifying functionality-oriented sys. –when to use functionality-oriented

7 7 http://libre.adacore.com © AdaCore 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.)

8 8 http://libre.adacore.com © AdaCore under the GNU Free Documentation License with Calendar; package Alerts is type Alert is private; procedure Handle (A : in out Alert); procedure Log (A : Alert); private type Alert is record Time_Of_Arrival : Calendar.Time; Cause : String (1.. 200); end record; end Alerts; with Calendar; package Alerts is type Alert is private; procedure Handle (A : in out Alert); procedure Log (A : Alert); private type Alert is record Time_Of_Arrival : Calendar.Time; Cause : String (1.. 200); end record; end Alerts; alerts.ads

9 9 http://libre.adacore.com © AdaCore 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

10 10 http://libre.adacore.com © AdaCore 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;

11 11 http://libre.adacore.com © AdaCore under the GNU Free Documentation License private type Alert (P : Priority) is record Time_Of_Arrival : Time; Cause : String (1.. 100); case P is when Low => null; when Medium => Technician : Person; when High => Engineer : Person; Ring_Alarm_At : Time; end case; end record; end Alerts; discriminant varian t record

12 12 http://libre.adacore.com © AdaCore under the GNU Free Documentation License Functionality-Oriented Org. –variant programming –modifying functionality-oriented sys. –when to use functionality-oriented

13 13 http://libre.adacore.com © AdaCore under the GNU Free Documentation License 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; end Handle; Variant Programming

14 14 http://libre.adacore.com © AdaCore under the GNU Free Documentation License procedure Some_Routine (A : in out Alert) is begin... case A.P is when Low =>... when Medium =>... when High =>... end case; end Some_Routine; Typical Routine for Alert Objects (version 1)

15 15 http://libre.adacore.com © AdaCore under the GNU Free Documentation License 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; Typical Routine for Alert Objects (version 2)

16 16 http://libre.adacore.com © AdaCore under the GNU Free Documentation License procedure Set_Alarm (A : in out Alert; Wait : Duration) is begin A.Ring_Alarm_At := A.Time_Of_Arrival + Wait; end Handle; Variant Programming is checked Constraint_Erro r raised if A.Priority /= High

17 17 http://libre.adacore.com © AdaCore 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; function Get_Alert return Alert; with Alerts; use Alerts; function Get_Alert return Alert; Returns an unconstrained Alert the discriminant value is not known at compile time

18 18 http://libre.adacore.com © AdaCore under the GNU Free Documentation License The case inside Handle selects the right to execute depending on the discriminant Handling code centralized in Handle with Alerts; use Alerts; with Get_Alert; procedure Process_Alerts is begin loop -- infinite loop declare A : Alert := Get_Alert; begin Handle (A); -- could have written Handle (Get_Alert); end; end loop; end Process_Alerts; with Alerts; use Alerts; with Get_Alert; procedure Process_Alerts is begin loop -- infinite loop declare A : Alert := Get_Alert; begin Handle (A); -- could have written Handle (Get_Alert); end; end loop; end Process_Alerts; Probably a blocking call

19 19 http://libre.adacore.com © AdaCore under the GNU Free Documentation License Functionality-Oriented Org. –variant programming –modifying functionality-oriented sys. –when to use functionality-oriented

20 20 http://libre.adacore.com © AdaCore 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)

21 21 http://libre.adacore.com © AdaCore under the GNU Free Documentation License Adding new functionality 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; It’s simple It’s simple: Use child subprograms/packages

22 22 http://libre.adacore.com © AdaCore 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

23 23 http://libre.adacore.com © AdaCore under the GNU Free Documentation License Adding a data type 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; Much more work Much more work: need to modify the spec...

24 24 http://libre.adacore.com © AdaCore 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;

25 25 http://libre.adacore.com © AdaCore under the GNU Free Documentation License 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;... ALL the routines !

26 26 http://libre.adacore.com © AdaCore 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 Get_Alert; procedure Process_Alerts is begin loop -- infinite loop Handle (Get_Alert); end loop; end Process_Alerts; with Alerts; use Alerts; with Get_Alert; procedure Process_Alerts is begin loop -- infinite loop Handle (Get_Alert); end loop; end Process_Alerts;

27 27 http://libre.adacore.com © AdaCore under the GNU Free Documentation License Functionality-Oriented Org. –variant programming –modifying functionality-oriented sys. –when to use functionality-oriented

28 28 http://libre.adacore.com © AdaCore 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


Download ppt "1 © AdaCore under the GNU Free Documentation License Franco Gasperoni"

Similar presentations


Ads by Google