90 likes | 237 Views
System Structures. Package Abstract Data Type. Package. Essential programming tools To develop a set of related operations and other entities, especially types, to test these thoroughly, and then to store them in an Ada program library for future use. Encapsulation.
E N D
System Structures Package Abstract Data Type
Package • Essential programming tools • To develop a set of related operations and other entities, especially types, to test these thoroughly, and then to store them in an Ada program library for future use
Encapsulation • Grouping a set of related entities in a well-defined module, with a clearly specified interface to other program • The way, we produce software components that are pre-developed and pre-tested for reusability within an organization or distribution in the wider world
Abstract Data Type (ADT) • A special kind of package that groups a type together with a complete set of operations for that type
Example of ADT - - Partial Specification of Package Ada.Calendar PACKAGE Ada.Calendar IS - - Standard Ada package for dates and times Type Time IS Private; SUBTYPE Year_Number IS Integer Range 1901..2099; SUBTYPE Month_Number IS Integer Range 1 ..12; SUBTYPE Day_Number IS Integer Range 1 ..31;
- - functions to get the current time - - and return its date components FUNCTION Clock RETURN Time; FUNCTION Year (Date: Time) RETURN Year_Number; FUNCTION Month (Date: Time) RETURN Month_Number; FUNCTION Day (Date: Time) RETURN Day_Number; END Ada. Calendar;
Example Program With Ada.Text_IO; With Ada.Calendar; With Ada.Integer_Text_IO; Procedure Todays_Date IS -- -- Finds and Dislay Today’s Date -- RightNow : Ada.Calendar.Time; ---current time ThisYear : Ada.Calendar.Year_Number; --current year ThisMonth: Ada.Calendar.Month_Number; --current year ThisDay : Ada.Calendar.Day_Number; --current year
Begin RightNow := Ada.Calendar.Clock; ThisYear := Ada.Calendar.Year(Date => RightNow ); ThisMonth := Ada.Calendar.Month(Date => RightNow ); ThisDay := Ada.Calendar.Day(Date => RightNow ); Ada.Text_IO.Put (Item => "Today's Date is "); Ada.Integer_Text_IO.Put (Item => ThisMonth, Width => 1); Ada.Text_IO.Put (Item => '/'); Ada.Integer_Text_IO.Put (Item => ThisDay, Width => 1); Ada.Text_IO.Put (Item => '/'); Ada.Integer_Text_IO.Put (Item => ThisYear, Width => 1); Ada.Text_IO.New_Line; End Todays_Date;