1 / 23

ITEC 320

ITEC 320. Lecture 24 OO in Ada (2). Review. Questions? Inheritance in Ada. Abstract types. What are they? Why are they used?. Abstract types. Example. What do you think this means?. package P is type T is abstract tagged record … end record; Procedure Op(X: T) is abstract;

winona
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? • Inheritance in Ada

  3. Abstract types • What are they? • Why are they used?

  4. Abstract types

  5. 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;

  6. 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.

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

  8. 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

  9. 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

  10. 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 …

  11. Ada.fin • Finished with Ada • What is different? • What is better? • What is worse? • Now moving on to C++

  12. C++ intro • History then • Coding

  13. C++ • History of C++… • “C++ was designed to provide Simula’s facilities for program organization together with C’s efficiency and flexibility for systems programming. “ • Write coding in assembly, C, C++….

  14. OO • Simula 67 • 1965 (Vietnam, civil rights, Thunderbirds debuted) • Based off of algol… • Introduced basics of OO programming that we use today • Classes, inheritance, class variables, instance variables, class methods (virtual)

  15. C • Multiple people using a computer at the same time… • Broken project called Multics…. • Need was still there, it became UNIX • Needed a language for the new OS… • CPL,BCPL,B, then C!

  16. Pictures C++ = + Simula 67 Beautiful yet impractical C Ridiculously fast, yet difficult to work with

  17. Java • Some parts are C-like • Memory management? • Designed not to fail You Computer

  18. C++ • Complete control • Assembly to OO • Memory management • Speed • Used widely Did you check if all seven pointers were non-null or only six? Do you feel lucky, well do ya? “If programming in Pascal is like being put in a straightjacket, then programming in C is like playing with knives, and programming in C++ is like juggling chainsaws.” – Anonymous

  19. Hello World #include <iostream> #include <string> using namespace std; intmain(intargc, char** argv) { string hello = "Hello World"; cout << hello << endl; return 0; } System libraries Standard namespace (functions?) Function definition, entry point for every C/C++ program (command line args) String class and initialization Print to console Return code of program to OS Command Prompt: vi hello.cpp g++ -o Hello hello.cpp ./Hello Returns 0, can be used with scripts

  20. Producing programs File.java File.class JVM Actual machine code javac java conversion file.cpp Machine code that executes file g++ –o file file.c

  21. Tools • g++ - Free C++ compiler • VI / Emacs / Crimson editor (or others) • putty and rucs / your own linux machine • C++ should be portable between windows and linux…it usually isn’t • Develop on platform you use to demonstrate…

  22. Memory Java C++

  23. Summary • Abstract types

More Related