Você está na página 1de 26

BITS Pilani

BITS Pilani
Hyderabad Campus

Dr.Aruna Malapati Asst Professor Department of CSIS

BITS Pilani
Hyderabad Campus

OBJECT ORIENTED PROGRAMMING CONCEPTS

Todays Agenda
Object Oriented paradigm Object Oriented concepts Basic terminology of Object Oriented principles

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Its about facing complex problems

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Abstraction + Decomposition + Organisation

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Functional Paradigm
We think in terms of functions acting on data
ABSTRACTION: Think of the problem in terms of a process that solves it. DECOMPOSITION: Break your processing down into smaller manageable processing units (functions). ORGANIZATION: Set up your functions so that they call each other (function calls, arguments, etc.)

FIRST: define your set of data structures (types, etc.) THEN: define your set of functions acting upon the data structures.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Object Oriented Paradigm


We think in terms of objects interacting: ABSTRACTION: Think in terms of independent agents (objects) working together. DECOMPOSITION: Define the kinds of objects on which to split the global task. ORGANIZATION: Create the appropriate number of objects of each kind. FIRST: Define the behavior and properties of objects of the different kinds we have defined. THEN: Set up objects of each kind and put them to work.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Object Oriented terms and concepts


An object represents a real person, place, event or transaction. A class is a group of similar objects. An instance is a specific member of a class. Languages based on OOP
Eiffel C++ Modulo-3 Ada 95 Java SmallTalk Microsoft .NET langages like C# and VC++ etc

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

What is object oriented programming?


Identifying objects and assigning responsibilities to these objects. Objects communicate to other objects by sending messages. Messages are received by the methods of an object
CS/IS F213 First Semester 2012-13 BITS Pilani, Hyderabad Campus

An object is like a black box. The internal details are hidden.

Benefits of Object Oriented Development


Promotes code reuse. Reduce code maintenance. Simplifies extending applications.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Objects
The world is made up of real world objects e.g. students, dogs, cars, cats, books.

Objects are the things our programs deal with.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

State and behavior


Every real world object has:
State information that the object stores. Behavior functionality of the object, i.e., what the object can do.

Example:
Consider a system managing university students. A student object has: State id, name, age, contact number, address, stage, completed courses, current courses, faculty, Behavior enroll in a new course, change contact number, change enrolment, choose degree,

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Basic Terminology
Abstraction is the representation of the essential features of an object. These are encapsulated into an abstract data type. Encapsulation is the practice of including in an object everything it needs hidden from other objects. The internal state is usually not accessible by other objects.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Basic Terminology: Inheritance


Inheritance means that one class inherits the characteristics of another class. This is also called a is a relationship:

A car is a vehicle A dog is an animal A teacher is a person

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Basic Terminology: Polymorphism


Polymorphism means having many forms. It allows different objects to respond to the same message in different ways, the response specific to the type of the object.

E.g. the message displayDetails() of the Person class should give different results when send to a Student object (e.g. the enrolment number).

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

The two steps of Object Oriented Programming


Making Classes: Creating, extending or reusing abstract data types. Making Objects interact: Creating objects from abstract data types and defining their relationships.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Polymorphism
Poly means many and morph means forms. In Java we have two types of polymorphisms Compile-Time [ Method Overloading] Run-Time [ Method Overriding]

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Polymorphism
An object has multiple identities, based on its class inheritance tree It can be used in different ways

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Unified Modeling Language


Modeling Language for specifying, Constructing, Visualizing and documenting software system and its components. Model -> Abstract Representation of the system [Simplified Representation of Reality] UML supports two types of models: Static - Dynamic

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Java Program Structure


Documentation Section
1. /** */ Documentation Comments 2. // Single Line Comment 3. /* */ Multi line Comments

Package Statement

Import Statements Interface Statements Class Definitions Main Method class

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

First Program
public class HelloWorld { public static void main(String args[]) { System.out.println("Hello World"); } }

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Compiling and Running

HelloWorld.java
source code

javac HelloWorld.java

compile

java HelloWorld

HelloWorld.class
bytecode

run

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Java byte code and interpreter


Byte code is an intermediate representation of the program (class). The Java interpreter starts up a new Virtual Machine.

The VM starts executing the users class by running its main() method.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Compiling/Executing a Java Application


Source Code Java Compiler ByteCode Java Interpreter << .java file>> << javac .java >>

<< .class file>>

<< java [name of class] >>

Machine Code
CS/IS F213 First Semester 2012-13 BITS Pilani, Hyderabad Campus

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Conclusions
Class is a collection of objects. Every object has state, behavior and identity.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Você também pode gostar