OBJECT ORIENTED PROGRAMMING

Similar documents
What is a Programming Paradigm

Elementary Concepts of Object Class

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

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

BASIC CONCEPT OF OOP


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

CHAPTER 5 GENERAL OOP CONCEPTS

Unit - IV CHAPTER - 13 INTRODUCTION TO OOP WITH C++ Part 1 Choose the best answer

What are the characteristics of Object Oriented programming language?

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

Object oriented programming Concepts

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

Sri Vidya College of Engineering & Technology

Inheritance and Polymorphism

Object-Oriented Programming (OOP) Fundamental Principles of OOP



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

Introduction to Object-Oriented Programming

Inheritance, and Polymorphism.

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

Object-Oriented Programming Concepts

Chapter 8: Creating Your Own Type Classes

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

Object-Oriented Programming

Object Oriented Pragramming (22316)

PROGRAMMING IN C++ COURSE CONTENT

Data Structures and Programming with C++

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

Object Oriented Programming using C++

Introduction to OOP. Procedural Programming sequence of statements to solve a problem.

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

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

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

Chapter3: Introduction to Classes and Objects

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

Chapter 5 Object-Oriented Programming

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

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

Downloaded from

Object Orientated Analysis and Design. Benjamin Kenwright

Computer Science 4U Unit 1. Programming Concepts and Skills Modular Design

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

CLASSES AND OBJECTS IN JAVA

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Basics of Object Oriented Programming. Visit for more.

Programming, numerics and optimization

INHERITANCE: EXTENDING CLASSES

PROGRAMMING LANGUAGE 2

Lecture 7: Classes and Objects CS2301

Objects First with Java A Practical Introduction using BlueJ

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

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

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

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

Defining Classes and Methods

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

Object Oriented Technology

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Chapter 5: Classes and Objects in Depth. Information Hiding

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI

Unit 1 : Principles of object oriented programming

Part 7 - Object Oriented Concepts Classes, Objects, Properties and Methods

C++ Important Questions with Answers

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

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

Data Structures using OOP C++ Lecture 3

OBJECT ORİENTATİON ENCAPSULATİON

CS-202 Introduction to Object Oriented Programming

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

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

Object Oriented Software Design

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Lecture 1. Abstraction

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

Inheritance, Polymorphism, and Interfaces

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

9/1/2015. Chapter 2 Using Objects. Objects and Classes. Using Objects. Using Objects. Using Objects. Classes. Ch. 1/2 Lab Time

Master of Computer Applications

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

Java Object Oriented Design. CSC207 Fall 2014

Objects First with Java A Practical Introduction using BlueJ

CHAPTER 1 Fundamentals of Distributed System. Issues in designing Distributed System

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

OBJECT ORIENTED PROGRAMMING

Inheritance and Polymorphism

Programmazione. Prof. Marco Bertini

Inheritance and Polymorphism

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

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

Compaq Interview Questions And Answers

EL2310 Scientific Programming

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Concepts of Programming Languages

JAVA GUI PROGRAMMING REVISION TOUR III

Software Architecture (Lesson 2) Object-Oriented Paradigm (1)

OBJECT ORIENTED SYSTEM DEVELOPMENT Software Development Dynamic System Development Information system solution Steps in System Development Analysis

Transcription:

1. Programming Paradigms OBJECT ORIENTED PROGRAMMING A programming methodology defines the methodology of designing and implementing programs using the key features and other building blocks (such as key words, functions, pre processor directives etc) of a programming language. Some of the important paradigms are: Procedural Programming Object based programming Object oriented programming 1.1 Procedural Programming Definition : Procedural programming is a programming paradigm that gives more emphasis to procedure than data. Advantage : Procedural Programming separates functions and data. So writing procedures separately was easy. Disadvantage : The Procedural programming is susceptible to design changes. The changes should be affecting more than one procedure in the program. The Procedural Programming leads to increased time and cost overheads during design changes. Example : C, Pascal etc 1.2 Object based Programming Definition : Object based programming is a programming paradigm that encloses data and associated meaningful functions in one single entity called a class. Advantage : i) Object based Programming localizes the implementation details. When any change is made the user interface is not affected. ii) It is considered as a sub set of Object oriented programming. iii) It overcomes the difficulties of Procedural Programming iv) It supports user defined types v) It implements information hiding and abstraction etc. Disadvantage : Object based programming cannot implement real world relationships that exist among objects. Example : Visual Basic 1.3 Object oriented programming Definition : Object oriented Programming is a programming paradigm that combines data and procedures in one single unit called object. Advantage : i) Object oriented Programming enables re use of code ii) It provides ease of comprehension. It makes the implementation of real world models easier.

iii) It provides ease of fabrication and maintenance. The concepts of data abstraction and data encapsulation provides a very clean design. iv) It can be easily redesigned and extended. The above facilities facilitate redesign and maintenance. Example : C++, Java 2. OOP Concepts: The Important OOP concepts are: Data Abstraction Data Hiding Data Encapsulation Object inheritance Polymorphism 2.1 Object: Object is an identifiable entity with some characteristics and behaviour. Examples: Car, Apple, Chair etc. A car is a collection of wheels, doors, seats, windows. These are its characteristics. A car can move, speed up, slow down, stop, park, etc. These are its behaviours. Thus we can put everything we know about a car in one object. 2.2 Implementing Objects: The characteristics or states are maintained with the help of variables or data items. The behaviour is implemented through functions or methods. 2.3 Encapsulation: Encapsulation is the wrapping up of characteristics and behaviour into one unit. The following things should be taken care during implementation of Encapsulation. i. Any thing that an object does not know or cannot do is excluded from the object. ii. Encapsulation is used to hide unimportant implementation details from other objects. iii) Packaging an object s variables within the protective custody of its methods is called encapsulation & this task is accomplished through Classes. 2.4 Classes: A class is a group of similar objects. Examples: Vehicle, Fruits, Furniture. A class can also be defined as a way to bind the data describing an entity and its associated functions together. Thus the class implements Encapsulation.

Encapsulation is having the benefits of modularity and information hiding. A class syntax for class definition is : class<class name> { private : //hidden data members/methods here protected : //(un important implementation details here public : //exposed implementation details here }; 2.5 Data Hiding: Data Hiding is a related concept of data abstraction. Unessential features or background details are hidden from the world. A class groups its members into three: Private Protected and Public The private & protected members remain hidden from outside world. Thus through private & protected members class enforces data hiding. 2.6 Data Abstraction: It is the act of representing the essential features without including the background details and explanations. The class gives the outside world only the essential data by using the concept of data hiding and the Public members contains the essential data for all the members. 2.7 Implementing Inheritance: Inheritance is implemented by specifying the name of the base class from which the class being defined (derived class) has to inherit from. class <class name> : <base class name> { derived class own features }

2.8 Abstract class: Abstract class is the one which defines an interface, but does not necessarily provide implementations for all its member functions. It is meant to be used as the base class from which other classes are derived. Example: Shape. It can suggest that shapes can have colour, size, sides etc. 2.9 Concrete class: A derived class that implements all the missing functionality is called a Concrete class. It is derived from an abstract class. Example: circle, rectangle etc. 2.10 Implementing Polymorphism: Polymorphism is the attribute that allows one interface to be used with different situation. Polymorphism is implemented through virtual functions, overloaded functions and overloaded operators. Overloading: The term overloading means a name having two or more distinct meanings. Thus an overloaded function refers to a function having more than one distinct meaning. Similarly when two or more distinct meanings are defined for an operator, it is said to be an overloaded operator. 2.11 Function overloading: A function name having several definitions that are differentiable by the number or types of their arguments is known as an overloaded function and this process is known as function overloading. float add(int a, int b); float add( float x, float y);

SOLVED PROBLEMS 1. What are the OOP concepts? 2 marks Ans: The Important OOP concepts are: Data Abstraction Data Hiding Data Encapsulation Object inheritance Polymorphism 2. Explain the concept of data abstraction and its implementation in C++. 2 marks Ans. It is the act of representing the essential features without including the background details and explanations. The class gives the outside world only the essential data by using the concept of data hiding and the Public members contains the essential data for all the members. Thus data abstraction is achieved with the help of class. 3. Explain the concept of data encapsulation and its implementation in C++. 2 marks Ans. Encapsulation is the wrapping up of characteristics and behaviour into one unit. A class is defined as a way to bind the data describing an entity and its associated functions together. Thus the class implements Encapsulation. 4. Explain the concept of data hiding and its implementation in C++. 2 marks Data Hiding is a related concept of data abstraction. Unessential features or background details are hidden from the world. A class groups its members into three: Private Protected and Public The private & protected members remain hidden from outside world. Thus through private & protected members class enforces data hiding. 5. Explain the benefits of data encapsulation. 1 mark Ans. Encapsulation is having the benefits of modularity and information hiding. 6. Explain the concept of object and its implementation in C++. 1 mark Ans. Object is an identifiable entity with some characteristics and behaviour. Examples: Car, Apple, Chair etc. The characteristics or states are maintained with the help of variables or data items. The behaviour is implemented through functions or methods. 7. Explain the concept of polymorphism and its implementation in C++. 1 mark Ans. Polymorphism is the attribute that allows one interface to be used with different situation.

Polymorphism is implemented through virtual functions, overloaded functions and overloaded operators. 8. Differentiate between abstract and concrete classes 2 marks Ans. Abstract class is the one which defines an interface, but does not necessarily provide implementations for all its member functions. It is meant to be used as the base class from which other classes are derived. Example: Shape. It can suggest that shapes can have colour, size, sides etc. A derived class that implements all the missing functionality is called a Concrete class. It is derived from an abstract class. Example: circle, rectangle etc. 9. State the advantages of Object Oriented Programming. 2 Marks Ans. i) Object oriented Programming enables re use of code ii) It provides ease of comprehension. It makes the implementation of real world models easier. iii) It provides ease of fabrication and maintenance. The concepts of data abstraction and data encapsulation provides a very clean design. iv) It can be easily redesigned and extended. The above facilities facilitate redesign and maintenance. 10Ḋifferentiate between Object Oriented and Object Based Programming. 2 Marks Ans. Though both OBP and OOP are object oriented, OBP does not support inheritance and there by polymorphism whereas these are supported by OOP. So OBP is considered as a subset of OOP. 11. Give any 2 examples for Object Oriented Programming. 1 Marks Ans. C++, Java 12. A function printchar is defined as 2 marks void printchar(char ch = *, int len = 40) { for(x = 0;x<len;x++) cout<<ch; cout<<endl; } How will you invoke the function for following output? i. to print * 40 times ii. to print = 40 times Ans. (i) printchar( ) (ii)printchar( = )