1 / 17

ITEC 320

ITEC 320. Lecture 24 OO in Ada (2). Review. Questions ? Reminder: Project 4 due on Tuesday Exam 2 next Friday Inheritance in Ada. Objectives. Polymorphism Abstract records Multiple inheritance. True OO. Tagging – Let Ada know you will be changing it. type Object is tagged r ecord

Download Presentation

ITEC 320

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITEC 320 Lecture 24 OO in Ada (2)

  2. Review • Questions? • Reminder: Project 4 due on Tuesday • Exam 2 next Friday • Inheritance in Ada

  3. Objectives • Polymorphism • Abstract records • Multiple inheritance

  4. True OO • Tagging – Let Ada know you will be changing it type Object is tagged record X_Coord: Float; Y_Coord: Float; end record; type Point is new Object with null record; type Circle is new Object with record Radius: Float; end record;

  5. Expanding • Passing records to functions / procedures Before: Procedure Test(testVar: in out testType) After: Procedure Test(testVar: in out testType’Class) What do you think this does?

  6. What to execute? • Have function that takes type from ancestor and one that takes the right type • Both have same name • Which one gets executed? • Specify behavior with overrides overriding – can also be not overriding procedure Operation(X: T);

  7. Expanding • Also applies to pointers Before: type testPtr is access all myClass After: type testPtr is access all myClass’Class type Cell is record Next: access Cell; element: testPtr; end record What would happen if we tagged this?

  8. Lessons • Ada still loves its strict typing • Bends the rules a bit with polymorphism • Or is it rule bending? • Remember the ‘class

  9. Using inheritance • What if you need to tell what object is what type? Checking: Procedure test(P: Person) is if P’Tag = Woman’Tag Or if P in Woman’Class then type Person is abstract tagged record Birth: Date end record; type Man is new Person with record Bearded: Boolean; end record; type Woman is new Person with record Children: Integer; end record;

  10. Abstract types

  11. Example • What do you think this means? package P is type T is abstract tagged record … end record; Procedure Op(X: T) is abstract; end p;

  12. Interfaces • Code package Q is type Intis interface; procedure Op(X: Int) is abstract; procedure N(X: Int) is null; procedure Action(X: Int’Class); end Q; Similar, except not allowed to contain information like a record.

  13. Why? • What do you think the purpose of abstract / interface capabilities are? • What scenarios do they allow? • What do they prevent?

  14. Shortcut • Java syntax • varName.methodName(params); • Ada syntax • procedureName(records); record X is … end record procedure Op(var: X, other params here)… Can be called with X.Op(other params); --Ada and Java sitting in a tree Note: has to be tagged and class wide

  15. Private variables • Keep the user away from your data! package Geometry is type Object is abstract tagged private; private type Object is tagged record x_coord : Float; y_coord : Float; end record; end Geometry; Requires a child package to inherit / use the Object class

  16. Multiple inheritance • C++ method • Diamond problem • Java method • Ada method • Can inherit from one tagged • All others have to be interfaces • Allows for procedures / functions • type NT is new T and Int1 and Int2 with …

  17. Summary • Variant Records

More Related