Upload
gneuromante-canaladaorg
View
1.151
Download
1
Embed Size (px)
DESCRIPTION
Author: Franco Gasperoni. License: GFDL
Citation preview
1http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Franco [email protected]://libre.act-europe.fr
2http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Copyright NoticeCopyright 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
3http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
4http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
When creating a new systemWhen creating a new systemyou must identify its ...you must identify its ...
• Data types(what kind of data will be manipulated)
• Functionalities(what kind of manipulations are allowed)
5http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Software System OrganizationSoftware System Organization
• Around its functionalities(structured programming)
• around its data types(object-oriented programming)
6http://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
7http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Design an alert systemDesign an alert systemfor an industrial plantfor an industrial plant
• log all the incoming alerts
• handle an alert (inform right people, etc.)
8http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
with Calendar;
package Alerts istype Alert is private;
procedure Handle (A : in out Alert);procedure Log (A : Alert);
privatetype Alert is record
Time_Of_Arrival : Calendar.Time;Cause : String (1 .. 200);
end record;end Alerts;
with Calendar;
package Alerts istype Alert is private;
procedure Handle (A : in out Alert);procedure Log (A : Alert);
privatetype Alert is record
Time_Of_Arrival : Calendar.Time;Cause : String (1 .. 200);
end record;end Alerts;
alerts.adsalerts.ads
9http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Having several kind of alertsHaving several kind of alerts
• Low
• Medium– dispatch a technician
• High– dispatch an engineer– if problem not fixed within a delay ring an alarm
10http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
with Calendar; use Calendar;with Persons; use Persons;
package Alerts istype 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);
privatetype Alert (P : Priority) is record ... end record;
end Alerts;
11http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
privatetype Alert (P : Priority) is record
Time_Of_Arrival : Time;Cause : String (1 .. 100);
case P iswhen Low =>
null;
when Medium =>Technician : Person;
when High =>Engineer : Person;Ring_Alarm_At : Time;
end case;end record;
end Alerts;
discriminant
variantrecord
12http://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
13http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
procedure Handle (A : in out Alert) isbegin
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 ProgrammingVariant Programming
14http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
procedure Some_Routine (A : in out Alert) isbegin
. . .case A.P is
when Low => . . .
when Medium =>. . .
when High =>. . .
end case;end Some_Routine;
Typical Routine for Alert ObjectsTypical Routine for Alert Objects(version 1)(version 1)
15http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
procedure Some_Routine (A : in out Alert) isbegin
. . .if A.P = Low then
. . .elsif A.P = Medium then
. . .elsif A.P = High then
. . .else
raise Internal_Error; -- defensive programmingend if;
end Some_Routine;
Typical Routine for Alert ObjectsTypical Routine for Alert Objects(version 2)(version 2)
16http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
procedure Set_Alarm (A : in out Alert; Wait : Duration) isbegin
A.Ring_Alarm_At := A.Time_Of_Arrival + Wait;end Handle;
Variant Programming is checkedVariant Programming is checked
Constraint_Error
raised ifA.Priority /= High
17http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Handling an AlertHandling 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 Alertthe discriminant value
is not knownat compile time
18http://libre.act-europe.fr © ACT Europe 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 isbegin
loop -- infinite loopdeclare
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 isbegin
loop -- infinite loopdeclare
A : Alert := Get_Alert;begin
Handle (A); -- could have written Handle (Get_Alert);end;
end loop;end Process_Alerts;
Probably a blocking call
19http://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
20http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Adding NEW Functionality...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)
21http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Adding new functionality Adding new functionality
procedure Alerts.New_Functionality (A : in out Alert) isbegin
. . .case A.P is
when Low => . . .
when Medium =>. . .
when High =>. . .
end case;end Alerts.New_Functionality;
It’s simpleIt’s simple: Use child subprograms/packages
22http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Adding a NEW Data Variant...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
23http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Adding a data typeAdding a data type
package Alerts is. . .
privatetype Alert (P : Priority) is record
. . . case P is
when Low => . . . when Medium => . . . when High => . . . when Emergency => . . .
end case;end record;
end Alerts;
Much more workMuch more work: need to modify the spec...
24http://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) isbegin
. . .case A.P is
when Low => . . .
when Medium =>. . .
when High =>. . .
when Emergency =>. . .
end case;end Some_Routine;
25http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
procedure Some_Routine (A : in out Alert) isbegin
. . .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 programmingend if;
end Some_Routine;
... ALL the routines !
26http://libre.act-europe.fr © ACT Europe under the GNU Free Documentation License
Important RemarkImportant 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 isbegin
loop -- infinite loopHandle (Get_Alert);
end loop;end Process_Alerts;
with Alerts; use Alerts;with Get_Alert;procedure Process_Alerts isbegin
loop -- infinite loopHandle (Get_Alert);
end loop;end Process_Alerts;
27http://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
28http://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