MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
MT311 (Oct 2007) Java Application Development Object-Oriented Programming Languages Tutorial 8.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Object-oriented Programming Concepts
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 24: Dynamic Binding COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Abstract Data Types and Encapsulation Concepts
C++ fundamentals.
MT311 Java Application Programming and Programming Languages Li Tak Sing ( 李德成 )
Programming Languages and Paradigms Object-Oriented Programming.
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
MT311 Java Programming and Programming Languages Li Tak Sing ( 李德成 )
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Comp 249 Programming Methodology Chapter 8 - Polymorphism Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal,
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
An Object-Oriented Approach to Programming Logic and Design
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Programming With Java ICS201 University Of Ha’il1 Chapter 8 Polymorphism and Abstract Classes.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
Chapter 12 Support for Object oriented Programming.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Object Oriented Software Development
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Object-Oriented Programming Chapter Chapter
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Chapter 4 Software. Chapter 4: Software Generations of Languages Each computer is wired to perform certain operations in response to an instruction. An.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Object Oriented Programming
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
ISBN Object-Oriented Programming Chapter Chapter
Chapter -6 Polymorphism
Introduction to OOP CPS235: Introduction.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
1 Lecture 23: Dynamic Binding (Section ) CSCI 431 Programming Languages Fall 2002 A compilation of material developed by Felix Hernandez-Campos.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
A Survey of Object-Oriented Concept Oscar Nierstrasz.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
ISBN Chapter 12 Support for Object-Oriented Programming.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
JAVA By Waqas.
Abstract Data Types and Encapsulation Concepts
OOP What is problem? Solution? OOP
11.1 The Concept of Abstraction
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Types of Programming Languages
Object Oriented Analysis and Design
Abstract Data Types and Encapsulation Concepts
Lecture 22 Inheritance Richard Gesick.
Introduction to Data Structure
Presentation transcript:

MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )

Implementing subprograms When a subprogram is called, an activation record instance (ARI) is created in the stack. It is destroyed when the subprogram returns. An ARI has a number of fields. Dynamic link and static link are two of them. Both of them are pointers pointing to the ARI of other subprograms. The meaning of the names reflects that the former needs information in execution time and the latter only needs information in compilation time.

Implementing subprograms In fact, the dynamic link of a subprogram always points to the ARI of the calling subprogram. As a subprogram can be called by different subprograms, to which ARI a dynamic link will point is not known at compile time. That is the reason why it is called dynamic. On the other hand, the static link of the ARI of a subprogram always points to the ARI of the static parent.

Implementing subprograms This information is known at compile time and therefore is called static.

ARI Other fields in ARI are parameters and local variables. So, consider the following subprogram: procedure proc1(int i) var j,k:integer; begin..... end;

ARI The ARI would have the following fields: – The storage for the parameter i (assume that it is passed by value) – The storage for local variables j and k. – The static link which points to the ARI of the static parent of the procedure. – The dynamic link which points to the ARI of the calling procedure. – return address

ARI

The ARI of the main program contains the following: – global variables

1. program A; 2. var a1: integer; 3. procedure B; 4. var b1: integer; 5. begin end; 8. procedure C; 9. var c1: integer; 10. procedure D; 11. var d1: integer; 12. begin end;

15. procedure E; 16. var e1: integer; 17. begin 18. C; 19. e1 := c1; 20. end; 21. begin end; 24. begin end;

ARI Draw the ARIs if the at this moment we have the following procedure call sequence: – A -> E ->C->D

Object Oriented Programming the three fundamental concepts underlying object-oriented programming: – data abstraction; – inheritance; and – polymorphism.

Data abstraction and encapsulation The encapsulation of an object is the representation of its most important features. For example, the encapsulation of a car may be a vehicle with four wheels. An abstract data type is the encapsulation of an object which includes all the subprograms that are used to manipulate it.

Data abstraction and encapsulation If all users of the object were restricted from manipulating it using these subprograms only, then the users’ code would be independent of the implementation of the object. This has two advantages: – The implementation of the abstract data type can be changed without affecting the users’ code. Thus these changes would not propagate to other parts of the system. This of course has one

condition, i.e., the interfaces of the subprograms should remain unchanged. – The implementation of the object is naturally separated from other parts of the system. Therefore the object can be tested individually. This would increase the reliability of the system.

Information hiding In order to ensure that users of an abstract data type manipulate it through a set of subprograms only, we have to find a way to prevent them from accessing the data structure of the data type directly. This is done by enforcing information hiding, i.e., removing the information concerning the internal attributes of the data type from any files released to the users.

Information hiding In Java, this is done by access modifier.

Inheritance and polymorphism Inheritance allows the programmer to inherit or derive new classes from an existing one. The new class may have additional attributes and methods. A new method would override an old one if the same name and parameter list were used. Overriding an existing method in a derived class is an important mechanism in fine-tuning an existing code.

Inheritance and polymorphism However, this mechanism would not be of much use without polymorphism. Polymorphism is the ability to invoke the correct version of an overridden method when the corresponding message is passed to an object. Polymorphism is closely related to dynamic binding.

Dynamic binding Dynamic binding means that the binding of a value to an item is to be done when a program is run. In this case, when a method of an object is invoked, the runtime environment will first check the true type of the object and then invoke the method that is defined for this object type.

Inheritance and polymorphism Inheritance and polymorphism are important in making software reusable. Without them, existing code could hardly be reusable because situations change from project to project. With inheritance and polymorphism, we can fine-tune an existing code by deriving new classes and add new attributes, new methods and override existing methods in the new classes.

Inheritance and polymorphism Polymorphism would ensure that the overridden methods would be invoked correctly.