chapter -1 concept of object oriented programming it’s need & requirement :- there are many...

13
Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language. But the basic reason behind invention of all languages is the need to handle the increasing complexity of programs that are reliable and maintainable .As the industry is growing rapidly, the need and requirements are changing according to the demands of Industry and these needs are increasing the complexity of software systems as well as competition in the industry. There are basic requirements to develop successful software & to meet them. Requirements: Language used should be capable of To represent real life entities of problems in system design. To reuse and extend modules. To develop modules those are tolerant to any changes in future. To increase software productivity, quality of software and decrease cost of software. To make software user friendly and provide security at the same time.

Upload: marshall-mcbride

Post on 29-Jan-2016

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING

 It’s Need & Requirement :-   There are many programming languages before Object Oriented Programming language. But the basic reason behind invention of all languages is the need to handle the increasing complexity of programs that are reliable and maintainable .As the industry is growing rapidly, the need and requirements are changing according to the demands of Industry and these needs are increasing the complexity of software systems as well as competition in the industry. There are basic requirements to develop successful software & to meet them.

Requirements: Language used should be capable of

To represent real life entities of problems in system design.To reuse and extend modules.To develop modules those are tolerant to any changes in future.To increase software productivity, quality of software and decrease cost of software.To make software user friendly and provide security at the same time.

 

Page 2: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Procedure oriented programming: In procedure oriented programming, the problem is considered as a sequence of instruction to be done such as reading, calculating & printing. A number of functions are written to accomplish these tasks. The primary focus is on function. A technical Programming Structure for procedure oriented Programming is given below.

Drawbacks: -  In large programs, it is very difficult to identify what data is issued by which function.It does not model real world problem. Because function are action orien ted & do not correspond to the elements of the problem. Object Oriented programming: - The fundamental behind oops is to combine into a single unit both data & function that operate on data, such a unit is called an oop. Oop treats data as critical element in the theory programming development & does not allow it to flow freely around the system. It ties data more closely to function that operates it & protects it to flow around the system accidentally. Features of OOPS :- 1.Focus is on objects.2.Data & function are tied together in data structure.3.Data structure as are designed such that they characterized object.4.Object may communicate with each other through functions.5.Data is hidden and cannot be accessed by external functions.6.New data and functions can be easily added whenever necessary. 

Page 3: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Advantages of OOPS :-

It offers a new & powerful way to cope with programming Complexity. It is clear, more reliable, easier to maintain program. It adds new oops features like encapsulation, inheritance polymorphism

etc. It provides better data hiding to programming. It provides templates, which are used to operate on different Data types. Through inheritance we can eliminate redundant code & extended the use

of existing classes. It is possible to map object in problem Domain to those programs It is easy to partition in a program based on object. Oops system can be easily upgraded from small to large system. Software complexity can be easily managed.

Object Oriented Language: -  The language should be support several of the object oriented

programming concept. They can be classified into Two categories. 

Object Based programming Language. Object Oriented programming Language.

  List Of Object Oriented Programming Languages:-

  1) Simula. 2) Smalltalk. 3) C++. 4) Eiffel. 5) Java. 6) Dot Net etc.

Page 4: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Applications of oops: -

• Real time system.• Object Oriented database• Artificial intelligence & expert sys.• Hypertext, hypermedia.• CAM/CAM sys.• Parallel programming.• Decision support & office automation system.• Simulation & modeling

Basic concept of oops: - Object: -  It is a basic run time entities in an object Oriented system. They may represent a person place, bank acc. A table of data or any item that the program must handle. Programming problem is analyzed in terms of objects and the nature of communication between them.

When program is executed, the object interacts by sending messages to one another.

Each object contains data and code to manipulate the data. Objects can interact without having to know details of each other’s data or code.

For example, if “customer” and “account” are two objects in a program, then customer object can send a message to the account object requesting for the bank balance. 

Page 5: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Classes: -

1. Classes that they contain data & code to manipulation data type.

2. Once class has been defined, we can create any number of objects belonging to that class.

3.For example, fruit is the class, the syntax used to create an object is fruit mango;

Where mango is the class variable, which is also called object.

4.Classes are user defined data types & behave like a built in types of a programming language.

Data Encapsulation : - It means wrapping of data and functions into a single unit(called class).

The data is not accessible to the outside world and only those functions, which are wrapped in the class, can access it.

These functions provide the interface between the object’s data and the program. This insulation of the data from direct access by the program is called data hiding.

 

Data Abstraction : - It refers to the act of representing essential features without including the

background details or explanation.Classes use the concept of abstraction and are defined as a list of abstract attributes

such as size, weight and cost and functions operate on these attributes.

Page 6: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

3.They encapsulate all the essential properties of the objects that are to be created. Since the classes uses the concept of data abstraction, they known as abstract data types.

4.It provides ability to create user defined data types.

Inheritance: - 1.It allows extension & reuse of existing the code without having rewritten the code from scratch.

2.Inheritance involves the creation of new classes from existing one.

3.Inheritance provides the important feature of OOP that is reusability.

4.The old class is referred as base class and new class is called the derived class. The new classes have combined features of both the classes.

5.There are different types of inheritance process like single inheritance, multiple inheritance, multilevel inheritance, hierarchical inheritance etc.

Polymorphism:  Polymorphism means many forms.It is the ability to take more than one form.

In object oriented programming, polymorphism refers to identically named method i.e. member functions that have a different behavior depending on the type of object they refers.

Page 7: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

3.In object oriented programming, polymorphism refers to identically named method i.e. member functions that have a different behavior depending on the type of object they refers.

4.For example, an operation may exhibit different behavior in different instances. The behavior depends upon the types of data used in the operation.

• There are basically two types of polymorphism.

1.Compile time polymorphism

2.Runtime polymorphism.

Dynamic binding: - Binding refers to the lining of a procedure call to the code to be executed in response to the call.

Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run time.

Dynamic binding is associated with polymorphism and inheritance.

  

Page 8: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Message passing:

• As the object oriented program consists of a set of objects that communicate with each other. The process of programming in an object-oriented language therefore involves the following basic steps:

1.Creating classes that defines objects and their behaviors.2.Creating objects from class definitions.3.Establishing communicate among objects.

1.Object communicates with one another by sending and receiving information.

2.A message for an object is a request for execution of a procedure, and therefore will invoke a function (procedure) in receiving object that generates the desired results.

3.Message passing involves specifying the name of the object, the name of the function (message) and the information to be sent. Objects have a life cycle. They can be created and destroyed. Communication with an object is feasible as long as it is alive.

Page 9: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Beginning With C++ :-

What is c++: - C++ is object oriented programming. It was developed By bjarne strousrup at & bell lab. C++ is an extension of with major ads of class construct feature & simula 67. Strousrup initially called new language c with classes how ever later in 1983 the name was changed to c++.

Comments: - C++ introduces New comment symbol “//” (double slash comment) start with this symbol terminated at the end of line. A comment may start from anywhere the line & what ever follows till the end of line is ignored there is no closing symbol This is a single line comment multiline are written as follows.

•// c++ prog.•/*

Data code */

Output operator : The ouput statement in program is Cout << “welcome to world of c++”;

Causes the string in quotation marks to be displayed on the screen.•The identifier cout is predefined object that represens the standard output stream in c++. Here, the output stream represents the screen. It is also possible to redirect the output to other output devices.•The operator << is called the insertion or put to operator. It inserts or sends the contents of the variable on its right to the object on its left.•The object cout has simple interface. If ‘str’ represents a string variable, then the following statement will display its contents Cout << str;•The operator << is the bit wise left-shift operator and it can be still used for this purpose.

Page 10: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Input operator:

He statement in program is cin >> number;

Is an input statement and causes the program to wait for the user to type in a number. The number keyed in is placed in the variable number.

•The identifier cin is predefined object in c++ that corresponds to the standard input stream. Here, the stream represents the keyboard.

•The operator >> is known as extraction or get from operator. It extracts or takes the value from the keyboard and assigns it to the variable on its.”.

Structure of c++ program: A Typical C++ program would contains four section as shown in the following figure.These section may be placed in separate code files and then compiled independently. 1.Header files include start of the program.

2.The class declaration are placed in header file.

3.Definition of member class go into another file.

4.The main program that uses the class is placed in third file.

Page 11: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Example :-

#include<iostream.h>#include<conio.h>

Class student{Int roll_no;Char name[10];Public:Void accept();};

Void student::accept(){Cout<<”enter student name and roll no”;Cin>>roll_no>>name;}

Void main(){Student s;s.accept();}

Page 12: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Concept of Structure: - The structure is a convenient tool for handling a group of logically related

data items. It is user defined data types. Structure provides a method for packing together the data different types of data. Once the structure type has been defined, we can create a variable of that structure type using declaration that same to built in type declaration.

Declaration a structure :- struct [struct_name]{

data_type member_name ; data_type member_name ;

. } [structure_variables];

For example:- struct stud { char name [20]; int roll_no; float total; };a1,a2,a3; or Struct stud a1,a2,a3;

The keyword struct declared stud as a new data type that can be hold 3 fields of different Data types. Fields are known as structure Member Or element. The identifier Stud which is referred to as struct name.

Page 13: Chapter -1 CONCEPT OF OBJECT ORIENTED PROGRAMMING It’s Need & Requirement :- There are many programming languages before Object Oriented Programming language

Union: - These are the derived data types same as structure. Both structure & union are used to group no of different variable together. Structure enables as to treat the same space for a no different Variables and union occupies the largest memory of member for all members. union a { int i; char i; char ch [2]; }key;

where union is a keyword, a is name of union and key is name of union variable.