Object-Oriented Programming Concepts

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

Classes - 2. Data Processing Course, I. Hrivnacova, IPN Orsay

Chapter 3 Objects and Classes

Classes and Objects. CGS 3416 Spring 2018

Introduction to Programming Using Java (98-388)

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

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

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

Programming II (CS300)

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

JAVA: A Primer. By: Amrita Rajagopal

Simple Java Reference

CLASSES AND OBJECTS. Fundamentals of Computer Science I

A foundation for programming. Classes and objects. Overview. Java primitive types. Primitive types Creating your own data types

ITI Introduction to Computing II

Object oriented programming Concepts

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

Chapter 6 Introduction to Defining Classes

Chapter 8 Objects and Classes

Defining Classes and Methods

Lecture 7: Classes and Objects CS2301

JAVA GUI PROGRAMMING REVISION TOUR III

ITI Introduction to Computing II

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

Recap of OO concepts. Objects, classes, methods and more. Mairead Meagher Dr. Siobhán Drohan. Produced by:

CLASSES AND OBJECTS. Fundamentals of Computer Science I

Chapter3: Introduction to Classes and Objects

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

Object Oriented Design: Identifying Objects

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

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

Java Object Oriented Design. CSC207 Fall 2014

Object-Oriented Programming. Objects. Objects. Objects

Defining Classes and Methods. Objectives. Objectives 6/27/2014. Chapter 5

CS101 Part 2: Practice Questions Algorithms on Arrays, Classes and Objects, String Class, Stack Class

Object Orientated Analysis and Design. Benjamin Kenwright

Structs. Comp Sci 1570 Introduction to C++ Introduction. Aggregate data. Example. General syntax Object initialization Initialization and access

Object-Oriented Programming in Processing

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology

Chapter 8 Objects and Classes. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Object Oriented Programming COP3330 / CGS5409

Programming II (CS300)

Programming II (CS300)

Computational Expression

CS1004: Intro to CS in Java, Spring 2005

Object Oriented Programming in C#

Methods and Data (Savitch, Chapter 5)

Object interactions Lecture 6

9 Working with the Java Class Library

Classes and Objects. COMP1400/INFS1609 Week 8. Monday, 10 September 12

OO Programming Concepts

Object-Oriented Programming, Classes

5. Defining Classes and Methods

Encapsulation. You can take one of two views of an object: internal - the structure of its data, the algorithms used by its methods

Lecture 18 Tao Wang 1

Inheritance, and Polymorphism.

Objects and Classes Lecture 2

UFCE3T-15-M Object-oriented Design and Programming

Object Oriented Programming

10. Java Classes. Classes - Technical. Example: Earthquake catalog. Classes - Conceptual

OBJECT ORİENTATİON ENCAPSULATİON

Comments are almost like C++

OBJECT ORIENTED PROGRAMMING

CMSC 132: Object-Oriented Programming II

Topic 27 classes and objects, state and behavior

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

13. Java Classes. Educational Objectives. Classes - Technical. Definition: Classes

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

Lecture 06: Classes and Objects

Objects and Classes. Basic OO Principles. Classes in Java. Mark Allen Weiss Copyright 2000

Chapter 4 Defining Classes I

EECS168 Exam 3 Review

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

Object-Oriented Programming

Object Oriented Programming

Objects and Classes -- Introduction

Data Structures using OOP C++ Lecture 3

COMPUTER PROGRAMMING (ECE 431) TUTORIAL 9

Elementary Concepts of Object Class

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

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

7. C++ Class and Object

10. Abstract Data Types

CMSC 132: Object-Oriented Programming II

Chapter 14 Abstract Classes and Interfaces

Objectives. Defining Classes and Methods. Objectives. Class and Method Definitions: Outline 7/13/09

Abstract Data Types (ADT) and C++ Classes

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

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

CLASSES AND OBJECTS IN JAVA

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

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

Imperative Languages!

Chapter 8 Objects and Classes Dr. Essam Halim Date: Page 1

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Binghamton University. CS-140 Fall Data Types in Java

CSC207 Week 2. Larry Zhang

Transcription:

Object-Oriented Programming Concepts Real world objects include things like your car, TV etc. These objects share two characteristics: they all have state and they all have behavior. Software objects are modeled after real-world objects in that they, too, have state and behavior. A software object maintains its state in variables and implements its behavior with methods. In an OO language like Java or C++, the basic building block is the object, an entity that has its own data (variables) and its own methods for manipulating that data and interacting with other objects. OOP refers to the art of decomposing an application into some number of objects that work together. An Object Methods Variables For e.g., a Circle object would need to describe its center (x and y coordinates) and its radius. This object must also be able to set its center coordinates or its radius, and report its radius to other object.

Description of a Circle object Data float x_coord // the x-coord of the center float y_coord // the y-coord of the center float radius // the radius Methods void setcenter(float x, float y) //accept two numbers and //set the coordinates to them void setcenter(float rad) //accept one number and set the //radius float getradius() // returns the radius value These variables and methods are known as instance variables and instance methods to distinguish them from class variables and class methods. In Java, everything is an object, with the exception of the primitive types of information like integers. Every Java program is a collection of cooperating objects, passing requests to other objects to perform their methods, and responding to similar requests from other objects. Objects communicate with each other by sending messages to each other. Message components include: 1. The object to whom the message is addressed. 2. The name of the method to perform. 3. Any parameters needed by the method. Objects don't need to be in the same process or even the same machine to send and receive messages to each other.

Benefits of Encapsulation Encapsulating related variables and methods into an object provides two major benefits to software developers: 1. Modularity: The source code for an object can be written and maintained independently of the source code for other objects. An object can also be passed around in the system. 2. Information Hiding: An object can maintain private information and methods that can be changed at any time without affecting other objects that depend on it. E.g. you don't need to know how a particular method is implemented; just how to use it. Classes A class is a blueprint or prototype that defines the variables and methods common to all objects of a certain kind. Example of the Circle class: Class Circle { private float x_coord; private float y_coord; private float radius; public void setcenter(float x, float y) { public void setcenter(float rad) { public float getradius() {

A class is used to instantiate (create an instance of) objects. Circle c1; //declaration of var c1 that creates a var (a //reference) that refers to an object of type Circle. c1 = new Circle(); //dynamically creates the object in //memory using the new keyword. To use this circle object, c1: c1.setcenter(1.0,2.0); float radius = c1.getradius(); Each object has its own set of instance variables. Values of these variables in one object can differ from the values in another object. Each object is associated with an instance method(s) but does not have its own copy of the method(s). Objects are created (instantiated) with the new keyword E.g. Circle c1 = new Circle(); The Circle() is called the constructor and specifies the type of object and any required parameters to create it. Another e.g. int hours = new Date().gethours(); Visibility modifiers (e.g. private) restrict access to variables and methods. So the following statement is illegal: float radius1 = c1.radius; //needs the getradius() method