Tuesday, October 20, 2015

Introduction to Object-Oriented Programming

Unit 1 :  Introduction to Object-Oriented Programming

Structure of  the Unit:
1.0       Objective
1.1       Paradigms of Programming Languages
1.2       What is OOPS?
1.3       Benefits of OOPS
1.4       Uses of Object-Oriented Programming
1.5       Advantages of Ojbect-Oriented Programming
1.6       Object-Oriented Language
1.7       Uses of C++
1.8       Summary
1.9       Self Assessment Questions

1.0  Objective

After studying this unit you will be able to understand :
n    The concept of  Paradigms and its techniques
n    Meaning of object-oriented Programming
n    Class, object, its properties and method
n    Benefits of OOP and applications of OPPS
n    Advantages and disadvantages of OOPS

1.1     Paradigms of Programming Languages

The term paradigm describes a set of techniques, methods, theories and standards that together represent a way of thinking for problem solving. According to [Wegner, 1988], paradigms are "patterns of thought for problem solving ". Language paradigms were associated with classes of languages. First the paradigms are defined. Thereafter, programming languages according to the different paradigms are classified. The language paradigms are divided into two parts:-  imperative and declarative paradigms. Imperative languages can be further as classified into procedural and object-oriented approach.
Declarative languages can classified into functional languages and logical languages.
Imperative Paradigms:
The meaning of imperative is "expressing a command or order". So, the programming languages in this category specify the step-by-step explaination of command. Imperative programming languages describe the details of how the results are to be obtained in terms of the underlying machine model. The programs specify step-by-step the entire set of transitions that the program goes through. The programs starts from an initial state, goes through the transitions and reaches a final state. Within this paradigm, we have the procedural approach and object-oriented approach.
Procedural Paradigm
Procedural Languages are statement oriented with the variables holding values. In this language, the execution of a program is modeled as a series of states of variable locations. We have two kinds of statements.   Non-executable statements and Executable statements.
Non-executable statements allocate memory, bind symbolic names to absolute memory locations and initialize memory.
Executable statements like computation, control flow, and input/output statements. The popular programming languages in this category are Ada, FORTRAN, BASIC, Algol, Pascal, COBOL, Modula, C etc.
Object-Oriented Paradigm
The object-oriented paradigm is centered on the concept of the object. Everything is focused on objects. Can you think what is an object? In this paradigm, program consists of two things: a set of objects and the way they interact with each other. Computation in this paradigm is viewed as the simulation of real world entities. The popular programming languages in this paradigm are : C++, Smalltalk and Java.
Declarative Paradigm
In this paradigm, programs declare or specify what is to be computed without specifying how it is to be achieved. Declarative programming is also known as value-oriented programming. Declarative languages describe the relationship between variables in terms of functions and inference rules. The language executor applies a fixed method to these relations to produce a desired result. It is mainly used in solving artificial intelligence and constraint-satisfaction problems. Declarative paradigm is further divided into two categories: Functional and Logical paradigms.

1.2     What is OOPS?

Object Oriented Programming System (OOPS) is a way of developing software using objects. Objects are the real world models, which are entities in themselves. They contain their own data and behaviour.
An object resembles the physical world. When something is called as an object in our world, we associate it with a name, properties, etc. It can be called or identified by name and/or properties it bears. When these real world objects are called, they act in some or the other way. Similarly, object in OOPS are called or referenced by the way of messages. Objects have their own internal world (data and function) and external interface to interact with the rest of the program (real world).
Thinking in terms of objects results from the close match between objects in the programming sense and objects in the real world. What kind of things become objects in object-oriented programs? The answer depends on your imagination, but here are some typical categories to start you thinking.
Physical Objects
ATM in Automated Teller Machines
Aircraft in an Air traffic control system
Elements of the Computer user Environment
Windows
Menus
Graphic Objects (lines, rectangles, circles)
Data Storage Constructs
Arrays
Stacks
Linked Lists
Human Entities
Employees
Students
Customers
Let us think about an object employee. The question that we should ask for this object design is: "What are the data items related to an Employee entity? and, What are the operations that are to be performed on this type of data?"
One possible solution for employee type may be:
Object :  Employee
Data: Name, DOB, Gender, Basic Salary, HRA, Designation, Department, Contact address, Qualification.
Operations: Find_Age, Compute_Salary, Find_address.
Create_new_employee, Delete_old_employee.
Object : Employee
DATA Name
DOB
Gender
Basic Salary
HRA
Designation
Department
Contact Address Qualification
....................
Functions
Find Age
Compute Salary
Find Addresses
Create- new_employee
Delete-old_employee

Representing of object
But now the obvious Question is: How are the objects defined?
The objects are defined via the classes.

Class 
Objects with similar properties are put together in a class. A class is a pattern, template, or blueprint for a category of structurally identical items (objects). OOPS programmers view Objects as instances of Class. Infact, objects are variables of the type Class. Once, class has been defined, we can create any number of objects belonging to that class. A class is thus a collection of objects of similar type.
Class contains basic framework, i.e., it describes internal organisation and defines external interface of an object. When we say a class defines basic framework, we mean that it contains necessary functionality for a particular problem domain. For example, suppose we are developing a program for calculator, in which we have a class called calculator, which will contain all the basic functions that exist in a real world calculator, like add, subtract multiply, etc., the calculator class will, thus, define the internal working of calculator and provides an interface through which we can use this class. For using this calculator class, we need to instantiate it, i.e., we will create an object of calculator class. Thus, calculator class will provide a blueprint for building objects. An object which is an instance of a class is an entity in itself with its own data members and data functions. Objects belonging to same set of class shares methods/functions of the class, but they have their own separate data values.
Calculator calc
Calculator calc will create an object calculator calc belonging to the class calculator. Class in OOPS contains its members and controls outside access, i.e., it provides interface for external access.
All the objects share same member data functions, but maintain separate copy of member data.
You can use class for defining a user defined data type. A class serves a plan, or a template that specifies what data and what functions will be included in an objects of that class. Defining the class does not create any objects. A class has meaning only when it is instantiated. For example, we can use a class employee directly.
Inheritance
Let us now consider a situation where two classes are generally similar in nature with just couple of differences. Would you have to re-write the entire class?
Inheritance is an important feature of OOPS that allows derivation of the new objects from the existing ones. It allows the creation of new class, called the derived class, from the existing classes called as base class.
The concept of inheritance allows the features of base class to be accessed by the derived classes, which in turn have their new features in addition to the old base class features. The original base class is also called the parent or super class and the derived class is also called as sub-class. This concept of inheritance provides the idea of receisability. This means that we can add additional features to an existing class without modigying it.
An example
Cars, mopeds, trucks have certain features in common, i.e., they all have wheels, engines, headlights, etc. They can be grouped under one base class called automobiles. Apart from these common features, they have certain distinct features which are not common like mopeds have two wheels and cars have four wheels, also cars use petrol and trucks run on diesel.
The derived class has its own features in addition to the class from which they are derived.
Let us extend our example of employee class in the context of Inheritance. After creating the class, Employee, you might make a sub-class called, Manager, which defines some manager-specific operations on data of the sub-class 'manager'. The feature which can be included may be to keep track of employee being managed by the manager.
We know that inheritance also promotes reuse. You do not have to start from scratch when you write a new program. You can simply reuse an existing repertoire of classes that have behaviour similar to what you need in the new program.
Data Abstraction and Encapsulation
Whenever we have to solve a problem then first we try to distinguish between the important and unimportant aspects of the problem. This is abstraction, thus, Abstraction identifies pattern and frameworks, and separate important and non-important problem spaces. Abstraction refers to the an act of representing essential features without including the background details.
To invent programs, you need to be able to capture the same kinds of abstractions as the problem have, and express them in the program design.
From the implementation point of view, a programmer should be concerned with "what the program is composed of and how does it works?" On the other hand, a user of the program is only concerned with "What it is and what it does."
All programming languages provides a way to express abstractions. In essence, abstraction is a way of grouping implementation details, hiding them, and giving them, at least to some extent, a common interface. For example, you have a group of functions that can act on a specific data structures. To make those functions easier to use by, you can take the data structure out of the interface of the entity/object by supplying a few additional functions to manage the data. Thus, all the work of manipulating the data structure, viz., allocating data, initialising, output of information, modifying values, keeping it up to date, etc., can be done through the functions. All that the users do is to call the functions and pass the structure to them.
With these changes, the structure has become an opaque token that other programmers never need to look inside. They can concentrate on what the functions do, not how the data is organised. You have taken the first step toward creating an object. Because an object completely encapsulates their data (hide it), users can think of them solely in terms of their behaviour.
The hidden data structure combines all of the functions that share it. So, an object is more than a collection of random functions; it is a grouping, a bundle of related behaviours that are supported by shared data.
This progression from thinking about functions and data structures to thinking about object behaviour is the essence of object-oriented programming. It may seem unfamiliar at first, but as you gain experience with object-oriented programming, you will find that it is a more natural way to think about things. By providing higher level of Abstractions, object-oriented programming language give us a larger vocabulary and a richer model to program in.
The wrapping up of data and function into a single unit is known as encapsulation. Encapsulation is the word which came from the word “CAPSULE” which to put something in a kind of shell. Encapsulation is a way of organizing data and methods into a structure by hiding the way the object is implemented. It prevents the access to data by any means other than those specified. Encapsulation therefore guarantees the integrity of the data contained in the object. Encapsulation defines the access levels for elements of that class. These access levels define the access rights to the data, allowing us to access the data by a method of that particular class itself.
Polymorphism
Polymorphism is another important OOP concept. Polymorphism means the ability to take more than one form. An operation may exhibit different behaviours in different instances. The behaviour depends on the data types used in the operation. Polymorphism is a Greek word. Polymorphism enables us to “program in the general” rathar than “program in the specific.” Polymorphism results from the fact that every class lives in its own name space. The names assigned within a class definition won’t conflict with names assigned anywhere outside it.

1.3     Benefits of OOP

OOP offers several benefits to both the program designer and the user. Object orientation contributes to the solution of many problems associated with the development and quality of software products. The new technology promises greater programmer productivity, better quality of software are and lesser maintenance cost. The main advantages of OOP are as follows :
n    Through inheritance, we can eliminate redundant code and extend the use of existing classes.
n    We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch This leads to saving of development time and higher productivity.
n    The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program.
n    It is possible to have multiple instances of an object to co-exist without any interference.
n    It is possible to map objects in the problem domain to those in the program.
n    It is easy to partition the work in a project based on objects.
n    The data-centered design approach enables us to capture more details of a model in implementable form.
n    Object-oriented systems can be easily upgraded from small to large systems.
n    Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler.
n    Software complexity can be easily managed.
While it is possible to incorporate all these features in an object-oriented system, their importance depends on the type of the project and the preference of the programmer.
Developing a software that is easy to use makes it hard to build. It is hoped that the objectoriented programming tools would help manage this problem.

1.4     Uses of Object-Oriented Programming

OOPS is not only a programming tool, but also a whole modeling paradigm. In addition to general problem solving, two of the upcoming object-oriented applications that are emerging very fast are:
System Software
As an object-oriented operating system, its architecture is organised into frameworks of objects that are hierarchically classified by function and performance. By that, we mean that the whole operating system can be found as made up of objects. The object oriented programming has been a great help for Operating system designers; it allowed them to break the whole operating system into simple and manageable objects.
It allowed them to reuse existing codes by putting similar objects in related classes. KDE (a well known desktop of Linux) developers have extensively used the concepts of object oriented programming.
Linux Kernel itself is a well known application of object oriented programming.
DBMS
Also known as Object Oriented Database Management System (OODBMS), OODBMS store data together with the appropriate methods for accessing it; the fundamental concept of object oriented programming, i.e., encapsulation is implemented in them which allows complex data types to be stored in database. The Complex datatypes are not supported in Relational Data Base Management Systems.
Every data type as well as its relations are represented as objects in OODBMS.
OODBMS have the following features:
n  Complex data types can be stored.
n  A wide range of data types can be stored in the same database (e.g., multimedia applications).
n  Easier to follow objects through time, this allows applications which keeps track of objects        which evolve in time.
The other promising area for application of OOP includes :
1.               Image Processing
2.               Pattern Recognition
3.               Computer Aided Design and Manufacturing
4.               Intelligent Systems
5.               Web Based Applications
6.               Distrubuted Compuring and Applications
7.               Enterprise Resource Planning
8.               Data Security and Management
9.               Mobile Conputing
10.            Parallel Computing

1.5     Advantages of Objective-Oriented Programming

The popularity of Object-oriented programming (OOP) was because of its methodology, which allowed breaking complex large software programs to simpler, smaller and manageable components. The costs of building large monolithic software were enormous. Moreover, the fundamental things in object oriented programming are objects which model real world objects. The following are the basic advantages of object-oriented systems:
n    Modular Design: The software built around OOP are modular, because they are built on objects and we know objects are entity in themselves, whose internal working is hidden from other objects and is decoupled from the rest of the program.
n    Simple approach: The objects, model real world entities, which results in simple program structure.
n    Modifiable: Because of its inherent properties of data abstraction and encapsulation, the internal working of objects is hidden from other objects. Thus, any modification made to them should not affect the rest of the system.
n    Extensible: The extension to the existing program for its adaptation to new environment can be done by simple adding few new objects or by adding new features in old classes/ types.
n    Flexible: Software built on object-oriented programming can be flexible in adapting to different situations because interaction between objects does not affect the internal working of objects.
n    Reusable: Objects once made can be reused in more than one program.
n    Maintainable: Objects are separate entities, which can be maintained separately allowing fixing of bugs or any other change easily..

1.6     Object-Oriented Language

Object-oriented programming is not the right of any particular language. OOP concepts can be implemented using language such as C and Pascal. However, programming becomes clumsy and may generate confusion when the programs grow large. The object-oriented language can be classified into two categories:
n    Object-based programming language
n    Object-oriented programming language
The object-based programming language is the style of programming that primarily supports encapsulation and object identity without supporting important features of OOP language such as polymorphism, inheritance and message based communications. Ada is one of the typical object-based programming language:
Object-based language = Encapsulation + Object identity
Object-oriented language incorporate all the features of object-based programming languages along with inheritance and polymorphism,
Object-oriented language = Object-based language + inheritance + polymorphism
Language that support these features include C++. Smalltalk, Object Pascal and Java.

1.7     Usage of C++

C++ is a versatile language for handling very large programs. It is suitable for virtually any programming task including development of editors, compilers, database, communication system and any complex real-life application systems.
n    Since C++ allows us to create hierarchy-related objects, we can build special objectsoriented libraries which can be used later by many programmers.
n    While C++ is able to map the real-world problem properly, the C part of C++ gives the language the ability to get close to the machine-level details.
n    C++ programs are easily maintainable and expandable.

1.8     Summary

The most popular phase till recently was procedure-oriented programming. The procedure-oriented programming employs top-down programming approach. Object oriented programming was invented to overcome the drawbacks of the procedure-oriented programming OOPs treats data as a critical element in the program development and does not allow it to flow freely. It ties data more closely to functions that operate on it in a data structure called class. The feature is called data encapsulation. Objects are instances of classes. Incapsulation of data from direct access by the program is call data hiding. Inheritance is the process by which objects of one class acquire properties of object of another class. Polymorphism means one name, multiple forms. It allows us to have more than one function with the same name in a program.

1.9  Self Assessment Questions

1.               What is procedure-oriented programming? What are its main charactersistics ?
2.               How are data and function organized in an object-oriented program?
3.               What kinds of things can become objects in OOP?
4.               What are the unique advantages of an object-oriented programming paradigm?
5.               Explain various application areas of object-oriented programming.



                                                                                      contact--
                                                                                        Ankit pundir
                                                                                        (ankitpundir623@gmail.com)
                                                                                                      thank you

No comments:

Post a Comment