Introduction to Object-Oriented Concepts in Fortran95

Size: px
Start display at page:

Download "Introduction to Object-Oriented Concepts in Fortran95"

Transcription

1 Introduction to Object-Oriented Concepts in Fortran95 Object-Oriented Programming (OOP) is a design philosophy for writing complex software. Its main tool is the abstract data type, which allows one to program in terms of higher level concepts than just numbers and arrays of numbers. In their mathematics, physicists are quite familiar with the power of abstraction, e.g., we express physics equations using the curl operator, rather than writing out all the components. But we have not used such abstractions very much in our programming. OOP includes a number of concepts which have proved useful in programming large projects. These are: 1. Information Hiding and Data Encapsulation 2. Function Overloading or Static Polymorphism 3. Abstract Datatypes, Classes and Objects 4. Inheritance 5. Dynamic Dispatch or Run-Time Polymorphism

2 Information Hiding and Data Encapsulation Perhaps the most important concept is that of information hiding. This means that information which is required in only one procedure should not be made known to other procedures which do not need this information. Like the CIA, procedures should be informed of data only on a need to know basis. This philosophy simplifies programming, because there is less detail one must be concerned about in programming and less opportunities to make mistakes. One way to achieve this is to encapsulate the data inside a derived type, and then allow only certain procedures (sometime called methods) to modify the data. One is prevented from modifying the data by any other means not provided by the programmer. Such encapsulation permits separation of concerns. One can separately write and debug pieces of a large program, without worrying about a new procedure causing inadvertent damage to an older procedure. Writing complex program becomes an order N problem, rather than an order N 2 problem.

3 Let s look at an example of what this means. Consider the following interface to a legacy Fortran77 fft procedure: subroutine fft1r(f,t,isign,mixup,sct,indx,nx,nxh) integer isign, indx, nx, nxh, mixup(nxh) real f(nx) complex sct(nxh), t(nxh)... rest of procedure goes here In this procedure, f is the data to be transposed, t is a temporary work array, mixup is a bit reversed table, sct is a sine/cosine table, indx is the power of 2 defining the length of the transpose, nx is the size of the f, and nxh is size of the remaining data, and isign is either the direction of the transform (-1,1) or a request to initialize the tables (0). To use this fft, one must get all of this data correct, there are many opportunities for mistakes. However, most of this data is relevant only internal details of performing the fft. The programmer only wants to worry about the data f and the direction of the transpose. Life would be much simpler if one could merely call call fft1(f,isign) without having to worry about the other details.

4 One of the reason all these details are exposed is that Fortran77 did not allow dynamic arrays. By using automatic and allocatable arrays, one can easily hide the scratch array t and the tables mixup and sct inside a wrapper function: subroutine fft1(f,indx,isign,nx,nxh) integer indx, isign, nx, nxh real f(nx) complex, dimension(nxh) :: t integer, dimension(:), allocatable, save :: mixup complex, dimension(:), allocatable, save :: sct if (isign==0) allocate(mixup(nxh),sct(nxh)) call fft1r(f,t,isign,mixup,sct,indx,nx,nxh) Thus the programmer does not have to worry about these things anymore and there is less opportunity for error. Fortran95 arrays encapsulate dimension information, and we can use this feature to remove all the dimension information from the interface: subroutine fft1(f,indx,isign) integer :: indx, isign, nx, nxh real, dimension(:) :: f complex, dimension(size(f)/2) :: t integer, dimension(:), allocatable, save :: mixup complex, dimension(:), allocatable, save :: sct nx = size(f); nxh = nx/2 if (isign==0) allocate(mixup(nxh),sct(nxh)) call fft1r(f,t,isign,mixup,sct,indx,nx,nxh)

5 We have successfully hidden from the programmer details about the fft that are not necessary to know to use the fft. Now the interface is much simpler and less error prone: call fft1(f,indx,isign) If one gets the interface down to its bare essentials, then it is unlikely to change in the future, even if the internal details of the procedure do change. For example, suppose on a given computer, there was an optimized fft which was much faster than the legacy fft1r. One could now replace the call to fft1r inside the wrapper function, and the users of the wrapper function would not have to change anything in their code. subroutine fft1(f,indx,isign)... call faster_fft1r(f,...)! different internal arguments end subroutine call fft1(f,indx,isign)! Note the call does not change Thus encapsulation allows one to change the implementation details of a procedure without impacting the rest of the program. This also allows concurrent development: different programmers can be modifying different pieces of a large program, without worrying about getting in each other s way, so long as the interfaces do not change.

6 We can improve this interface even further by noting that the argument indx which determines the length of the fft and the internal tables mixup and sct need to be consistent with one another. The tables are created when the parameter isign = 0: call fft1r(f,indx,isign=0)! create tables But when the fft is called later, the indx parameter might different. call fft1(f,kndx,isign=1)! wrong value of indx. Part of the problem here is that the legacy fft1r is actually used to perform two completely different operations, table initialization and transposition. It is better to have two different functions perform two different operations. But the tables are private arrays stored inside the wrapper function fft1. How can another procedure initialize that table? There are several ways to do that. One way is to put the tables inside a module which is shared by all the procedures in the module, as follows:

7 module fft1 integer, save :: saved_indx integer, dimension(:), allocatable, save :: mixup complex, dimension(:), allocatable, save :: sct contains subroutine new_fft_table(indx) integer :: indx, isign, nx, nxh saved_indx = indx isign = 0 nx = 2**saved_indx; nxh = nx/2 allocate(mixup(nxh),sct(nxh)) call fft1r(f,t,isign,mixup,sct,indx,nx,nxh) end subroutine new_fft_table! create fft tables subroutine fft1(f,isign)! perform fft integer :: indx, isign, nx, nxh real, dimension(:) :: f complex, dimension(size(f)/2) :: t nx = 2**saved_indx; nxh = nx/2 call fft1r(f,t,isign,mixup,sct,indx,nx,nxh) end subroutine fft1 end module fft1 One can use these procedures as follows: use fft1 call new_fft_table(indx) call fft1(f,isign=1)! create new fft table! indx no longer in argument

8 We should also create a third procedure in this module to deallocate the tables if we will no longer perform any ffts. subroutine delete_fft_table() deallocate(mixup,sct) end subroutine delete_fft_table! delete fft tables One other feature we can add is access control. If we add the following lines to the beginning of the module: module fft1 private public: new_fft_table, delete_fft_table, fft1 then the fft tables cannot be accessed from outside the module. The only way to manipulate the table is via the new_fft_table and delete_fft_table procedures. As a student exercise, think about additional error checks one can add inside these procedures, e.g., how to prevent calling an fft if the table has not been created. Thus we have grouped together all operations related to ffts into a single module. Such grouping is also part of the concept of encapsulation. Information hiding and data encapsulation are arguably the most useful and important concepts in object-oriented programming.

9 Function Overloading or Static Polymorphism We have already encountered this concept in earlier lectures. Function overloading refers to using the same procedure name but performing different operations based on argument type. Fortran77 has always had this feature. For example, the function real() means different things depending on its type. integer :: i real :: a complex :: z a = real(i) a = real(z)! converts integer to real! takes real part of complex z In Fortran95, generic functions allow user defined functions to also have this feature. For example, there are many different types of FFTs, real to complex, complex to complex, one dimensional, two dimensional, single precision, double precision, etc. In Fortran77 one had remember different names for each of these FFTs. Since it is unambiguous what each of these do, Fortran95 allows one to use the same name for all of them, using generic interfaces: interface fft module procedure fft1rc module procedure fft1cc... end interface! define generic name fft

10 so long as each of these functions have different argument types. subroutine fft1rc(f) real, dimension(:) :: f subroutine fft1cc(f) complex, dimension(:) :: f subroutine fft2rc(f) real, dimension(:,:) :: f! argument is real array! argument is complex array! argument is real 2D array and so on. It is easy to overdo function overloading, however. You should use it only when it is obvious what you intend to happen. You should avoid using it if it obfuscates your intention. For example, by overloading different procedures with a generic name such as solve, you may not remember later which solver you actually intended, without carefully studying all the argument types in all your modules. You still want a human being to be able to read your code and easily determine what it is supposed to be doing. Function overloading is sometimes called static polymorphism because the actual function being called is determined (resolved) at compile time and not at run time.

11 Abstract Datatypes, Classes and Objects An abstract data type or class encapsulates a user defined data type along with the operations that one can perform on that type. For example, consider a class called Personnel designed to manipulating personnel records in a database. (This example comes from Henderson and Zorn). The data we encapsulate are a person s social security number and name. The functions we provide create and delete a record, print a record and obtain a social security number from a record. In Fortran95 a class looks like: module Personnel_class type Personnel private integer :: ssn character*12 :: firstname, lastname end type Personnel contains subroutine new_personnel(this,s,fn,ln)... subroutine delete_personnel(this)... subroutine print_personnel(this,printssn)... function getssn_personnel(this) result(ssn)... end module Personnel_class

12 A variable of this type is called an object. It is declared as follows: type (Personnel) :: person The components of a derived type are called the class data members. They are often declared private, so that individual components are not accessible outside the class. The procedures defined in the class are called class member functions. Generally, they provide the only means by which one can manipulate Personnel objects. One function which is always necessary is the constructor, to initialize a record. For example: subroutine new_personnel(this,s,fn,ln)! Constructor type (Personnel), intent (out) :: this integer, intent (in) :: s character(len=*), intent (in) :: fn, ln this%ssn = s! store social security number this%firstname = fn! store first name this%lastname = ln! store last name end subroutine new_personnel We can then create a person record for Paul as follows: program database use Personnel type (Personnel) :: person call new_personnel(person, , Paul, Jones )

13 By convention, the first argument in each method is the class type, and is commonly called this (in C++) or self (in other OO languages). In most OO languages, the first argument is not explicitly declared, but is available. A destructor is often defined to delete a Personnel object. In Fortran95, this is only necessary if the Personnel type has a pointer component. In our case, we will define a destructor to merely nullify the data: subroutine delete_personnel(this)! Destructor type (Personnel), intent (inout) :: this this%ssn = 0! nullify social security number this%firstname =! nullify first name this%lastname =! nullify last name end subroutine delete_personnel One can then delete the contents of Paul s person record as follows: call delete_personnel(person) Since the components of the personnel type are private, one cannot print them out directly: print *, person%ssn! Cannot print out ss number

14 Instead one has to provide a method to obtain the private components, for example print *, getssn_personnel(person)! this is OK. where we define a function to obtain the social security number: function getssn_personnel(this) result(ssn) type (Personnel), intent (in) :: this integer :: ssn ssn = this%ssn! extract the private component end function getssn_personnel We can also provide a function the print out the entire record: subroutine print_personnel(this) type (Personnel), intent (in) :: this print *, this%ssn, this%firstname, this%lastname end subroutine print_personnel

15 Although it may seem a unnecessarily complicated to make the components private, it has the advantage that one can change the components and those using this class do not need to modify their old code. For example, suppose that we decided at a later date to add an optional age field to the Personnel type: type Personnel private integer :: ssn, age character*12 :: firstname, lastname end type Personnel We create a new constructor: subroutine new_personnel_age(this,s,fn,ln,a) type (Personnel), intent (out) :: this integer, intent (in) :: s, a character(len=*), intent (in) :: fn, ln this%ssn = s! store social security number this%age = a! store age this%firstname = fn! store first name this%lastname = ln! store last name end subroutine new_personnel_age

16 We can continue to use the older constructor and the new one by using generic functions. First we rename the original constructor: subroutine new_personnel_orig(this,s,fn,ln) Then we define the generic interface interface new_personnel module procedure new_personnel_orig module procedure new_personnel_age end interface so that the name new_personnel now has two meanings. All of the old code works as before, and new code can use the new feature: type (Personnel), dimension(2) :: person call new_personnel(person(1), , Paul, Jones ) call new_personnel(person(2), , Pat, Smith,21)... call delete_personnel(person(1))! delete first record Pat Smith s age is recorded, Paul s is not. We might also wish to change how the print method works, e.g., suppose we wish to print to a file instead of to a console. The print method can be modified accordingly.

17 The public interface to a class presents an abstract type to the outside world. By requiring the outside world to use only these interfaces, keeping the internal details of a class private, the internal data cannot be corrupted, and the implementation of methods can be changed without impacting others.

Inheritance parent child contains

Inheritance parent child contains Inheritance Inheritance is a mechanism to create a hierarchy of classes in which a parent (or base) class contains the common properties of the hierarchy and child (or derived) classes can modify (or specialize)

More information

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year Object Oriented Programming Assistant Lecture Omar Al Khayat 2 nd Year Syllabus Overview of C++ Program Principles of object oriented programming including classes Introduction to Object-Oriented Paradigm:Structures

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

High Level Classes in UPIC Framework

High Level Classes in UPIC Framework High Level Classes in UPIC Framework The purpose of the High Level Classes is to encapsulate large pieces of code that the programmer does not wish to modify. They also provide a template for constructing

More information

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file? QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The

More information

What does it mean by information hiding? What are the advantages of it? {5 Marks}

What does it mean by information hiding? What are the advantages of it? {5 Marks} SECTION ONE (COMPULSORY) Question #1 [30 Marks] a) Describe the main characteristics of object-oriented programming. {5 Marks Encapsulation the ability to define a new type and a set of operations on that

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++

More information

Lists. Michael P. Fourman. February 2, 2010

Lists. Michael P. Fourman. February 2, 2010 Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce

More information

Week 8: Operator overloading

Week 8: Operator overloading Due to various disruptions, we did not get through all the material in the slides below. CS319: Scientific Computing (with C++) Week 8: Operator overloading 1 The copy constructor 2 Operator Overloading

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Objectives To review the concepts and terminology of object-oriented programming To discuss some features of objectoriented design 1-2 Review: Objects In Java and other Object-Oriented

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

QUIZ Friends class Y;

QUIZ Friends class Y; QUIZ Friends class Y; Is a forward declaration neeed here? QUIZ Friends QUIZ Friends - CONCLUSION Forward (a.k.a. incomplete) declarations are needed only when we declare member functions as friends. They

More information

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2016) ramana@cs.columbia.edu Lecture-2 Overview of C C++ Functions Structures Pointers Design, difference with C Concepts of Object oriented Programming Concept

More information

A simplified method for implementing run-time polymorphism in Fortran95

A simplified method for implementing run-time polymorphism in Fortran95 Scientific Programming 12 (2004) 45 55 45 IOS Press A simplified method for implementing run-time polymorphism in Fortran95 Viktor K. Decyk a,b and Charles D. Norton a a Jet Propulsion Laboratory, California

More information

Module 10 Inheritance, Virtual Functions, and Polymorphism

Module 10 Inheritance, Virtual Functions, and Polymorphism Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:

More information

Programming Tips for Plugins

Programming Tips for Plugins Programming Tips for Plugins Chad Neufeld Centre for Computational Geostatistics Department of Civil & Environmental Engineering University of Alberta Working in a university based research environment

More information

Lecture 18 Tao Wang 1

Lecture 18 Tao Wang 1 Lecture 18 Tao Wang 1 Abstract Data Types in C++ (Classes) A procedural program consists of one or more algorithms that have been written in computerreadable language Input and display of program output

More information

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module Basic Class Design Goal of OOP: Reduce complexity of software development by keeping details, and especially changes to details, from spreading throughout the entire program. Actually, the same goal as

More information

VIRTUAL FUNCTIONS Chapter 10

VIRTUAL FUNCTIONS Chapter 10 1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions

More information

C++ Inheritance and Encapsulation

C++ Inheritance and Encapsulation C++ Inheritance and Encapsulation Private and Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance 1 Private Members Private members

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Objectives To review the concepts and terminology of object-oriented programming To discuss some features of objectoriented design 1-2 Review: Objects In Java and other Object-Oriented

More information

CIS 110: Introduction to Computer Programming

CIS 110: Introduction to Computer Programming CIS 110: Introduction to Computer Programming Lecture 22 and 23 Objects, objects, objects ( 8.1-8.4) 11/28/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline Object-oriented programming. What is

More information

Outline. CIS 110: Introduction to Computer Programming. Any questions? My life story. A horrible incident. The awful truth

Outline. CIS 110: Introduction to Computer Programming. Any questions? My life story. A horrible incident. The awful truth Outline CIS 110: Introduction to Computer Programming Lecture 22 and 23 Objects, objects, objects ( 8.1-8.4) Object-oriented programming. What is an object? Classes as blueprints for objects. Encapsulation

More information

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas What is this class about? While this class is called Design Patterns, there are many other items of critical

More information

Chapter 12 Object-Oriented Programming. Starting Out with Games & Graphics in C++ Tony Gaddis

Chapter 12 Object-Oriented Programming. Starting Out with Games & Graphics in C++ Tony Gaddis Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics in C++ Tony Gaddis Addison Wesley is an imprint of 2010 Pearson Addison-Wesley. All rights reserved. 12.1 Procedural and Object-Oriented

More information

PROGRAMMING LANGUAGE 2

PROGRAMMING LANGUAGE 2 31/10/2013 Ebtsam Abd elhakam 1 PROGRAMMING LANGUAGE 2 Java lecture (7) Inheritance 31/10/2013 Ebtsam Abd elhakam 2 Inheritance Inheritance is one of the cornerstones of object-oriented programming. It

More information

Object oriented programming Concepts

Object oriented programming Concepts Object oriented programming Concepts Naresh Proddaturi 09/10/2012 Naresh Proddaturi 1 Problems with Procedural language Data is accessible to all functions It views a program as a series of steps to be

More information

Introduction to Object- Oriented Programming

Introduction to Object- Oriented Programming Introduction to Object- Oriented Programming Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en_us

More information

Midterm 2. 7] Explain in your own words the concept of a handle class and how it s implemented in C++: What s wrong with this answer?

Midterm 2. 7] Explain in your own words the concept of a handle class and how it s implemented in C++: What s wrong with this answer? Midterm 2 7] Explain in your own words the concept of a handle class and how it s implemented in C++: What s wrong with this answer? A handle class is a pointer vith no visible type. What s wrong with

More information

Assignment 1: grid. Due November 20, 11:59 PM Introduction

Assignment 1: grid. Due November 20, 11:59 PM Introduction CS106L Fall 2008 Handout #19 November 5, 2008 Assignment 1: grid Due November 20, 11:59 PM Introduction The STL container classes encompass a wide selection of associative and sequence containers. However,

More information

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

CS6301 PROGRAMMING AND DATA STRUCTURES II QUESTION BANK UNIT-I 2-marks ) Give some characteristics of procedure-oriented language. Emphasis is on doing things (algorithms). Larger programs are divided

More information

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics

Inf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics Inf1-OP Inf1-OP Exam Review Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 20, 2017 Overview Overview of examinable material: Lectures Week 1

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

Table 2 1. F90/95 Data Types and Pointer Attributes. Data Option. (Default Precision) Selected-Int-Kind

Table 2 1. F90/95 Data Types and Pointer Attributes. Data Option. (Default Precision) Selected-Int-Kind Chapter 2 Data Types Any computer program is going to have to operate on the available data. The valid data types that are available will vary from one language to another. Here we will examine the intrinsic

More information

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET VB.NET Module 1: Getting Started This module introduces Visual Basic.NET and explains how it fits into the.net platform. It explains how to use the programming tools in Microsoft Visual Studio.NET and

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

ENCAPSULATION AND POLYMORPHISM

ENCAPSULATION AND POLYMORPHISM MODULE 3 ENCAPSULATION AND POLYMORPHISM Objectives > After completing this lesson, you should be able to do the following: Use encapsulation in Java class design Model business problems using Java classes

More information

Reusing this material

Reusing this material Modules Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-ncsa/4.0/deed.en_us

More information

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented

More information

Data Structure. Lecture#2: Data Structures and Algorithms. U Kang Seoul National University. U Kang (2016) 1

Data Structure. Lecture#2: Data Structures and Algorithms. U Kang Seoul National University. U Kang (2016) 1 Data Structure Lecture#2: Data Structures and Algorithms U Kang Seoul National University U Kang (2016) 1 In This Lecture Learn what to consider in selecting right data structures Understand the need for

More information

Lecturer: William W.Y. Hsu. Programming Languages

Lecturer: William W.Y. Hsu. Programming Languages Lecturer: William W.Y. Hsu Programming Languages Chapter 9 Data Abstraction and Object Orientation 3 Object-Oriented Programming Control or PROCESS abstraction is a very old idea (subroutines!), though

More information

Chapter 10 Introduction to Classes

Chapter 10 Introduction to Classes C++ for Engineers and Scientists Third Edition Chapter 10 Introduction to Classes CSc 10200! Introduction to Computing Lecture 20-21 Edgardo Molina Fall 2013 City College of New York 2 Objectives In this

More information

Modern Fortran OO Features

Modern Fortran OO Features Modern Fortran OO Features Salvatore Filippone School of Aerospace, Transport and Manufacturing, salvatore.filippone@cranfield.ac.uk IT4I, Ostrava, April 2016 S. Filippone (SATM) Modern Fortran OO Features

More information

1 of 8 3/28/2010 8:03 AM C++ Special Topics Home Class Info Links Lectures Newsgroup Assignmen This is a short review of special topics in C++ especially helpful for various assignments. These notes are

More information

CGS 2405 Advanced Programming with C++ Course Justification

CGS 2405 Advanced Programming with C++ Course Justification Course Justification This course is the second C++ computer programming course in the Computer Science Associate in Arts degree program. This course is required for an Associate in Arts Computer Science

More information

Department of Computer science and Engineering Sub. Name: Object oriented programming and data structures Sub. Code: EC6301 Sem/Class: III/II-ECE Staff name: M.Kavipriya Two Mark Questions UNIT-1 1. List

More information

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C

More information

UPIC Framework designed to help construct Plasma PIC calculations by student programmers.

UPIC Framework designed to help construct Plasma PIC calculations by student programmers. Frameworks A framework is a unified environment containing all the components needed for writing code for a specific problem domain. Its goal is the rapid construction of new codes by reuse of trusted

More information

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C

More information

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

Chapter 4. Fortran Arrays

Chapter 4. Fortran Arrays Chapter 4. Fortran Arrays Fortran arrays are any object with the dimension attribute. In Fortran 90/95, and in HPF, arrays may be very different from arrays in older versions of Fortran. Arrays can have

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 4 : Classes & Objects Lecture Contents What is a class? Class definition: Data Methods Constructors Properties (set/get) objects

More information

2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET

2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET 2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET Introduction Elements of this syllabus are subject to change. This five-day instructor-led course provides students with the knowledge

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

UMBC CMSC 331 Final Exam

UMBC CMSC 331 Final Exam UMBC CMSC 331 Final Exam Name: UMBC Username: You have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for answers that are needlessly wordy

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Chapter 12 continue 12.6 Case Study: Payroll System Using Polymorphism This section reexamines the CommissionEmployee- BasePlusCommissionEmployee hierarchy that we explored throughout

More information

Operator overloading

Operator overloading 1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Create a Java project named week9

Create a Java project named week9 Objectives of today s lab: Through this lab, students will explore a hierarchical model for object-oriented design and examine the capabilities of the Java language provides for inheritance and polymorphism.

More information

QUIZ. Can you find 5 errors in this code?

QUIZ. Can you find 5 errors in this code? QUIZ Can you find 5 errors in this code? QUIZ What (if anything) is wrong with this code? public: ; int Constructor argument need! QUIZ What is meant by saying that a variable hides another? I.e. have

More information

Ch. 11: References & the Copy-Constructor. - continued -

Ch. 11: References & the Copy-Constructor. - continued - Ch. 11: References & the Copy-Constructor - continued - const references When a reference is made const, it means that the object it refers cannot be changed through that reference - it may be changed

More information

6.005 Elements of Software Construction Fall 2008

6.005 Elements of Software Construction Fall 2008 MIT OpenCourseWare http://ocw.mit.edu 6.005 Elements of Software Construction Fall 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 6.005 elements

More information

Classwide Programming 1

Classwide Programming 1 Classwide Programming 1 OO Definitions Type extension Tagged types 1 Object-Oriented Programming Method of program construction that facilitates: writing reusable software components supporting programming

More information

Defining Your Own Functions/Methods

Defining Your Own Functions/Methods Chapter 4 Defining Your Own Functions/Methods What is in This Chapter? Object-Oriented Programming (OOP) involves creating objects of our own. In this set of notes, we will discuss how to write functions

More information

9/21/2010. Based on Chapter 2 in Advanced Programming Using Visual Basic.NET by Bradley and Millspaugh

9/21/2010. Based on Chapter 2 in Advanced Programming Using Visual Basic.NET by Bradley and Millspaugh Building Multitier Programs with Classes Based on Chapter 2 in Advanced Programming Using Visual Basic.NET by Bradley and Millspaugh The Object-Oriented Oriented (OOP) Development Approach Large production

More information

Lesson Plan. Subject: OBJECT ORIENTED PROGRAMMING USING C++ :15 weeks (From January, 2018 to April,2018)

Lesson Plan. Subject: OBJECT ORIENTED PROGRAMMING USING C++ :15 weeks (From January, 2018 to April,2018) Lesson Plan Name of the Faculty Discipline Semester :Mrs. Reena Rani : Computer Engineering : IV Subject: OBJECT ORIENTED PROGRAMMING USING C++ Lesson Plan Duration :15 weeks (From January, 2018 to April,2018)

More information

Programming 2. Object Oriented Programming. Daniel POP

Programming 2. Object Oriented Programming. Daniel POP Programming 2 Object Oriented Programming Daniel POP Week 5 Agenda 1. Modifiers: friend 2. Objects Wrap-up last week Self-reference Modifiers: static const mutable Object Oriented Programming Friends (I)

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras

Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras Module 12B Lecture - 41 Brief introduction to C++ Hello, welcome

More information

Objects, Subclassing, Subtyping, and Inheritance

Objects, Subclassing, Subtyping, and Inheritance Objects, Subclassing, Subtyping, and Inheritance Brigitte Pientka School of Computer Science McGill University Montreal, Canada In these notes we will examine four basic concepts which play an important

More information

CPS 506 Comparative Programming Languages. Programming Language

CPS 506 Comparative Programming Languages. Programming Language CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support

More information

Cpt S 122 Data Structures. Introduction to C++ Part II

Cpt S 122 Data Structures. Introduction to C++ Part II Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function

More information

CS304 Object Oriented Programming Final Term

CS304 Object Oriented Programming Final Term 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing

More information

HST 952. Computing for Biomedical Scientists Lecture 5

HST 952. Computing for Biomedical Scientists Lecture 5 Harvard-MIT Division of Health Sciences and Technology HST.952: Computing for Biomedical Scientists HST 952 Computing for Biomedical Scientists Lecture 5 Outline Recursion and iteration Imperative and

More information

Welcome. Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at BST

Welcome. Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at BST Welcome Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at 15.00 BST Modern Fortran: F77 to F90 and beyond Adrian Jackson adrianj@epcc.ed.ac.uk @adrianjhpc Fortran Ancient History (1967)

More information

Programming, numerics and optimization

Programming, numerics and optimization Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428

More information

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR 603203 DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS QUESTION BANK (2017-2018) Course / Branch : M.Sc CST Semester / Year : EVEN / II Subject Name

More information

What is an algorithm?

What is an algorithm? Reminders CS 142 Lecture 4 ADTs & Objects Program 1 was assigned - Due on 1/27 by 11:55pm Spring 2015 2 Object-Oriented Programming (OOP) OOP Definitions Imagine: You and your programming team have written

More information

Object-Oriented Programming. Lecture 16 CS 565 4/10/08

Object-Oriented Programming. Lecture 16 CS 565 4/10/08 Object-Oriented Programming Lecture 16 CS 565 4/10/08 Object-Based Programming View basic features found in object-based systems: objects dynamic dispatch encapsulation of state inheritance self-reference

More information

1. Write two major differences between Object-oriented programming and procedural programming?

1. Write two major differences between Object-oriented programming and procedural programming? 1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 4 : Classes & Objects Lecture Contents What is a class? Class definition: Data Methods Constructors Properties (set/get) objects

More information

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. Chapter 12 OOP: Creating Object- Oriented Programs McGraw-Hill Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. Objectives (1 of 2) Use object-oriented terminology correctly. Create

More information

Programming II. Modularity 2017/18

Programming II. Modularity 2017/18 Programming II Modularity 2017/18 Module? Lecture Outline Evolution and history of programming languages Modularity Example History of Programming Programming Paradigms How and why languages develop? How

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (pronobis@kth.se) Overview Overview Wrap Up Introduction to Object Oriented Paradigm More on and Members Operator Overloading Last time Intro to C++ Differences between C and C++ Intro to OOP Today Object

More information

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

More information

CS1150 Principles of Computer Science Objects and Classes

CS1150 Principles of Computer Science Objects and Classes CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8

More information

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 4 : Classes & Objects Lecture Contents What is a class? Class definition: Data Methods Constructors Properties (set/get) objects

More information

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java

More information

CORE JAVA TRAINING COURSE CONTENT

CORE JAVA TRAINING COURSE CONTENT CORE JAVA TRAINING COURSE CONTENT SECTION 1 : INTRODUCTION Introduction about Programming Language Paradigms Why Java? Flavors of Java. Java Designing Goal. Role of Java Programmer in Industry Features

More information

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance? CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 5: Inheritance & Polymorphism Lecture Contents 2 What is Inheritance? Super-class & sub class Protected members Creating subclasses

More information

Object Oriented Programming

Object Oriented Programming Binnur Kurt kurt@ce.itu.edu.tr Istanbul Technical University Computer Engineering Department 1 Version 0.1.2 About the Lecturer BSc İTÜ, Computer Engineering Department, 1995 MSc İTÜ, Computer Engineering

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information