Introduction to Object-Oriented Programming

Similar documents
Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

JAVA: A Primer. By: Amrita Rajagopal

Data Abstraction. Hwansoo Han

Inheritance. OOP: Inheritance 1

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

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

Inheritance. Finally, the final keyword. A widely example using inheritance. OOP: Inheritance 1

OBJECT ORIENTED PROGRAMMING

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Inheritance and Polymorphism

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation

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

Inheritance and Polymorphism

Inheritance and Polymorphism

The object-oriented approach goes a step further by providing tools for the programmer to represent elements in the problem space.

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

EL2310 Scientific Programming

G Programming Languages - Fall 2012

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Polymorphism Part 1 1

Topics. Modularity and Object-Oriented Programming. Dijkstra s Example (1969) Stepwise Refinement. Modular program development

CSE 307: Principles of Programming Languages

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

PROGRAMMING IN C++ COURSE CONTENT

What is a Programming Paradigm

Chapter 10 Classes Continued. Fundamentals of Java

Overview. OOP: model, map, reuse, extend. Examples of objects. Introduction to Object Oriented Design

Programmazione. Prof. Marco Bertini

Lecture Notes on Programming Languages

2D1358 Object Oriented Program Construction in C++ Exercises & Labs. Course Registration / Accounts. Course Literature

Object oriented programming Concepts

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

CPS 506 Comparative Programming Languages. Programming Language

STRUCTURING OF PROGRAM

More C++ : Vectors, Classes, Inheritance, Templates

EL2310 Scientific Programming

OO Frameworks. Introduction. Using Frameworks

Object Oriented Programming. Java-Lecture 11 Polymorphism

The University Of Michigan. EECS402 Lecture 06. Andrew M. Morgan. Savitch Ch. 6 Intro To OOP Classes Objects ADTs.

Chapter 10 :: Data Abstraction and Object Orientation

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

2 rd class Department of Programming. OOP with Java Programming

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

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

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

Chapter 9 :: Data Abstraction and Object Orientation

Introduction to Computers and Java

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

Object Oriented Programming. C++ 6 th Sem, A Div Ms. Mouna M. Naravani

CS-202 Introduction to Object Oriented Programming

MechEng SE3 Lecture 7 Domain Modelling

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

10. Abstract Data Types

Advantages of Object Oriented Programming :- Features of Object Oriented Programming :- Advantages Of Object Oriented Programming :

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

What are the characteristics of Object Oriented programming language?

Object Oriented Programming

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Software Design and Analysis for Engineers

What about Object-Oriented Languages?

C++ Programming: Polymorphism

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading

Short Notes of CS201

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Lecture 6 Introduction to Objects and Classes

write the functions inside as well as outside the class. So in C++, they are called member functions and not methods.

JAVA METHODS OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES

Classes, objects, methods and properties

Programming in the Large II: Objects and Classes (Part 2)

CS201 - Introduction to Programming Glossary By

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

1. Software Systems Complexity, OO Paradigm, UML

Object Oriented Software Design II

COSC252: Programming Languages: Abstraction and OOP. Jeremy Bolton, PhD Asst Teaching Professor. Copyright 2015 Pearson. All rights reserved.

Object Oriented Software Design II

DOWNLOAD OR READ : OBJECT ORIENTED PROGRAMMING IN C BY ROBERT LAFORE 3RD EDITION PDF EBOOK EPUB MOBI

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Chapter 1: Object-Oriented Programming Using C++

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

BASIC CONCEPT OF OOP

Introduction to Java and OOP. Hendrik Speleers

EL2310 Scientific Programming

Object Oriented Programming. Solved MCQs - Part 2

Chapter 6 Introduction to Defining Classes

Sri Vidya College of Engineering & Technology

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Chapter 8: Class and Method Design

Inheritance and Substitution (Budd chapter 8, 10)

Programming Languages & Paradigms PROP HT Course Council. Subprograms. Meeting on friday! Subprograms, abstractions, encapsulation, ADT

VALLIAMMAI ENGINEERING COLLEGE

Chapter3: Introduction to Classes and Objects

Goals of the Lecture OO Programming Principles

Inheritance, Polymorphism and the Object Memory Model

An Introduction to Object Orientation

Lecture 7: Classes and Objects CS2301

Transcription:

Introduction to Object-Oriented Programming Objects and classes Abstract Data Types (ADT). Encapsulation OOP: Introduction 1

Pure Object-Oriented Languages Five rules [Source: Alan Kay]: Everything in an object. A program is a set of objects telling each other what to do by sending messages. Each object has its own memory (made up by other objects). Every object has a type. All objects of a specific type can receive the same messages. Java breaks some of these rules in the name of efficiency. OOP: Introduction 2

The Object Concept An object is an encapsulation of data. An object has identity (a unique reference), state, also called characteristics behaviour An object is an instance of an abstract data type. An abstract data type is implemented via a class. OOP: Introduction 3

Abstract Data Type (ADT) An ADT is a collection of objects (or values) and a corresponding set of methods. An ADT encapsulates the data representation and makes data access possible at a higher level of abstraction. Example 1: A set of vehicles with operations for starting, stopping, driving, get km/liter, etc.. Example 2: A time interval, start time, end time, duration, overlapping intervals, etc. OOP: Introduction 4

Encapsulation and Information Hiding Data can be encapsulated such that it is invisible to the "outside world". Data can only be accessed via methods. Data Function Function Function send message Data Method Method Method Procedural ADT OOP: Introduction 5

Encapsulation and Information Hiding, cont. What the "world" cannot see it cannot depend on! The object is a "fire-wall" between the object and the "world". The hidden data and methods can be changed without affecting the "world". Client interface Visible data and methods Hidden data and methods OOP: Introduction 6

Class A description of the common properties of a set of objects. A concept. A class is a part of a program. Class vs. Object Object A representation of the properties of a single instance. A phenomenon. An object is part of data and a program execution. OOP: Introduction 7

Type and Interface An object has type and an interface. Account balance() withdraw() deposit() Type Interface To get an object To send a message Account a = new Account() a.withdraw() OOP: Introduction 8

Instantiating Classes An instantiation is a mechanism where objects are created from a class. Always involves storage allocation for the object. A mechanism where objects are given an initial state. Static Instantiating In the declaration part of a program. A static instance is implicitly created Dynamic Instantiating In the method part of a program. A dynamic instance is created explicitly with a special command. OOP: Introduction 9

Interaction between Objects Interaction between objects happens by messages being send. A message activates a method on the calling object. An object O1 interacts with another object O2 by calling a method on O2 (must be part of the client interface). "O1 sends O2 a message" O1 and O2 must be related to communicate. The call of a method corresponds to a procedure call in a nonobject-oriented language such as C or Pascal. O1 message message O3 O2 message OOP: Introduction 10

Phenomenon and Concept A phenomenon is a thing in the "real" world that has individual existence. A concept is a generalization, derived from a set of phenomena and based on the common properties of these phenomena. Characteristics of a concept A name Intension, the set of properties of the phenomenon Extension, the set of phenomena covered by the concept. OOP: Introduction 11

Classification and Exemplification A classification is a description of which phenomena that belongs to a concept. An exemplification is a phenomenon that covers the concept Concept classification exemplification Phenomenon OOP: Introduction 12

Aggregation and Decomposition An aggregation consists of a number of (sub-)concepts which collectively is considered a new concept. A decomposition splits a single concept into a number of (sub-)concepts. Concept Concept Concept Concept decomposition aggregation Concept Concept Concept Concept OOP: Introduction 13

Aggregation and Decomposition, Example Idea: make new objects by combining existing objects. Reusing the implementation! Car start() drive() Engine Gearbox Doors[4] OOP: Introduction 14

Generalization and Specialization Generalization creates a concept with a broader scope. Specialization creates a concept with a narrower scope. Concept A Concept B specialization Concept C generalization Concept D Vehicle Car Hatchback Stationcar Sedan Truck Pickup OOP: Introduction 15

Generalization and Specialization, Example Inheritance: get the interface from the general class. Objects related by inheritance are all of the same type. Shape draw() resize() Circle draw() resize() Line draw() resize() Rectangle draw() resize() Square draw() resize() OOP: Introduction 16

Code Example void dosomething (Shape s){ s.draw; s.resize; } Circle c = new Circle(); Line l = new Line(); Rectangle r = new Rectangle (); dosomething (c); dosomething (l); dosomething (r); // dynamic binding Polymorphism: One piece of code works with many all shape object. Dynamic binding: Who polymorphism is implemented. OOP: Introduction 17

Structuring by Program or Data? What are the actions of the program vs. which data does the program act on. Top-down: stepwise program refinement Bottom-up: Focus on the stable data parts then add methods, Object-oriented programming is bottom-up. Programs are structure with outset in the data. OOP: Introduction 18

Java Program Structure // comments about the class public class MyProg { // comments about the main method public static void main (String[] args) { } method body method header } OOP: Introduction 19

Byte Code vs. Executable MyProg.java MyProg.cpp javac MyProg.java Java Class File MyProg.class Portable Byte Code Java Virtual Machine Operating System gcc MyProg.cpp -o myprog.exe Executable myprog.exe Operating System OOP: Introduction 20

History of Java 1990 Oak (interactive television, big failure) 1994 Java (for the Internet) Main feature: "Write Once, Run Any Where" => wrap the operating system so they all look the same. Designed for: A fresh start (no backward compatibility) "Pure" OOP: C++ Syntax, Smalltalk style Improvements over C++ much harder to write a bad program Internet programming Very hard to create a virus Run in a web browser (and at the server) There is a speed issue (high hopes for Java 1.4) OOP: Introduction 21

Everything resides in a class Difference from C/C++ variables and methods No global variables or methods No local static variables No separation of declaration and implementation (no header files). No explicit pointer operations No preprocessor (but something similar) Has fewer "dark corners" Has a much larger standard library OOP: Introduction 22

Summary Classes are "templates". All objects are instances of classes. An ADT is implemented in a class Encapsulation Key feature Separation of interface from implementation It is not possible to access the private parts of an object OOP: Introduction 23