0% found this document useful (0 votes)
12 views

Chapter 2

1. The document discusses the evolution of programming languages from first to fifth generation languages. It describes the characteristics of each generation and some examples. 2. It then covers different programming paradigms including monolithic, procedural, structured, and object-oriented programming. The key features and advantages/disadvantages of each paradigm are summarized. 3. Finally, it introduces some core concepts of object-oriented programming including classes, objects, and methods. Classes define the structure and behavior of objects, and methods define the operations objects can perform.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Chapter 2

1. The document discusses the evolution of programming languages from first to fifth generation languages. It describes the characteristics of each generation and some examples. 2. It then covers different programming paradigms including monolithic, procedural, structured, and object-oriented programming. The key features and advantages/disadvantages of each paradigm are summarized. 3. Finally, it introduces some core concepts of object-oriented programming including classes, objects, and methods. Classes define the structure and behavior of objects, and methods define the operations objects can perform.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

1

Python Programming
Using Problem Solving Approach

Reema Thareja

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


CHAPTER 2
Introduction to Object Oriented
Programming (OOP)
2

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Computer Programming
Programming languages are used to create programs that control the behavior of a system, to express algorithms, or as a mode of
human communication.
The selection of language for writing a program depends on the following factors:
• The type of computer hardware and software on which the program is to be executed
• The type of program
• The expertise and availability of the programmers
• It must have the features to write the application.
• It should have built-in features that support the development of software
• Lower development and maintenance costs
• The programming language must be stable and capable enough to support even more than the expected simultaneous users.
• Ease with which new features (or functions) can be added to the existing program.
• It should be portable.
3
• Better speed of development
© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.
First Generation: Machine Language

All the commands and data values are expressed using 0s and 1s, corresponding to the off and on electrical states in a
computer.

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Second Generation: Assembly Language
It used symbolic codes, also known as mnemonic codes, which are easy-to-remember abbreviations, rather than
numbers. Examples of these codes include ADD for add, CMP for compare, and MUL for multiply.
An assembly language statement consists of a label, an operation code, and one or more operands.
Labels are used to identify and refer instructions in the program.

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Third Generation: High-level Language
The third generation was introduced to make the languages more programmer-friendly.
A translator is needed to translate the instructions written in a high-level language into the computer-executable
machine language. Such translators are commonly known as interpreters and compilers.
The 3GLs make it easy to write and debug a program and give a programmer more time to think about its overall
logic.

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Fourth Generation: Very High-level Languages
4GLs are a little different from their prior generation because they are non-procedural.
While using a non-procedural language, programmers define what they want the computer to do but they do not
supply all the details of how it has to be done.

Although there is no standard rule that defines a 4GL, certain characteristics include the following:
• The instructions of the code are written in English-like sentences.
• They are non-procedural, so users concentrate on the ‘what’ instead of the ‘how’ aspect of the task.
• The code written in a 4GL is easy to maintain.
• The code written in a 4GL enhances the productivity of programmers, as they have to type fewer lines of code to get
something done. A programmer supposedly becomes 10 times more productive when he/she writes the code using a
4GL than using a 3GL. 7

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Fifth-generation Programming Language

Fifth-generation programming languages (5GLs) are centered on solving problems using the constraints given to a
program rather than using an algorithm written by a programmer.

These languages are widely used in artificial intelligence research.

Typical examples of 5GLs include Prolog, OPS5, Mercury, and Visual Basic.

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Monolithic Programming
Programs written using monolithic programming languages such as assembly
language and BASIC consist of global data and sequential code. The global data
can be accessed and modified (knowingly or mistakenly) from any part of the
program, thereby, posing a serious threat to its integrity.
Monolithic programs have just one program module as such programming
languages do not support the concept of subroutines. Therefore, all the actions
required to complete a particular task are embedded within the same
application itself. This not only makes the size of the program large but also
makes it difficult to debug and maintain.

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Procedural Programming
In procedural languages, a program is divided into n number of subroutines that access
global data. To avoid repetition of code, each subroutine performs a well-defined task. A
subroutine that needs the service provided by another subroutine can call that subroutine.
Therefore, with ‘jump’, ‘Go To’, and ‘call’ instructions, the sequence of execution of
instructions can be altered.
Advantages
• The only goal is to write correct programs.
• Programs were easier to write as compared to monolithic programming.
Disadvantages
• Writing programs is complex.
• No concept of reusability.
• Requires more time and effort to write programs.
10
• Programs are difficult to maintain.
© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.
• Global data is shared and therefore may get altered (mistakenly).
Structured Programming
Structured programming, also referred to as modular programming.
Advantages
Efficient, correct programs that are easy to understand, debug and change.
• Modules enhance programmer’s productivity.
Many programmers can work on a single, large program
• A structured program takes less time to be written than other programs. • Each module
performs a specific task.
• Each module has its own local data.
First to introduce the concept of functional abstraction.
Disadvantages
• Not data-centered.
• Global data is shared and therefore may get inadvertently modified. 11

• Main focus on functions. © OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.
Object Oriented Programming (OOP)
In the object oriented paradigm, the list and the associated operations are treated as one entity known as an object.

The striking features of OOP include the following:


• The programs are data centered.
• Programs are divided in terms of objects and not procedures.
• Functions that operate on data are tied together with the data.
• Data is hidden and not accessible by external functions.
• New data and functions can be easily added as and when required.
• Follows a bottom-up approach for problem solving.

12

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Classes, Objects, and Methods
A class is used to describe something in the world, such as occurrences, things,
external entities, and so on. A class provides a template or a blueprint that describes
the structure and behavior of a set of similar objects. Once we have the definition for
a class, a specific instance of the class can be easily created.
A class can have multiple instances or objects. Every object contains some data and
procedures. They are also called methods.
A method is a function associated with a class. It defines the operations that the object
can execute when it receives a message. In OOP language, only methods of the class
can access and manipulate the data stored in an instance of the class (or object).
Two objects can communicate with each other through messages. An object asks
another object to invoke one of its methods by sending it a message. 13

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Inheritance
Inheritance is a concept of OOP in which a new class is created from an existing class. The
new class, often known as a sub-class, contains the attributes and methods of the parent class
The new class, known as sub-class or derived class, inherits the attributes and behavior of
the pre-existing class, which is referred to as super-class or parent class. The inheritance
relationship of sub- and super classes generates a hierarchy. Therefore, inheritance relation
is also called ‘is-a’ relation. A sub-class not only has all the states and behaviors associated
with the super-class but has other specialized features (additional data or methods) as well.
The main advantage of inheritance is the ability to reuse the code. When we want a
specialized class, we do not have to write the entire code for that class from scratch. We can
inherit a class from a general class and add the specialized code for the sub-class.

14

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Polymorphism, Containership and Reusability
Polymorphism refers to having several different forms. It is related to methods. Polymorphism is a concept that enables the
programmers to assign a different meaning or usage to a method in different contexts. Polymorphism can also be applied to
operators. For example, we know that operators can be applied only on basic data types that the programming language
supports. Therefore, a + b will give the result of adding a and b. If a = 2 and b = 3, then a + b = 5. When we overload the +
operator to be used with strings, then Fraction1 + Fraction2 adds two fractional numbers and returns the result.
Containership is the ability of a class to contain object(s) of one or more classes as member data. For example, class One can
have an object of class Two as its data member. This would allow the object of class One to call the public functions of class
Two. Here, class One becomes the container, whereas class Two becomes the contained class. Containership is also called
composition.
Reusability means developing codes that can be reused either in the same program or in different programs. Python gives
due importance to building programs that are reusable. Reusability is attained through inheritance, containership, and
polymorphism. 15

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Data Abstraction and Encapsulation

Data abstraction refers to the process by which data and functions are defined in such a way that only essential details
are revealed and the implementation details are hidden. The main focus of data abstraction is to separate the interface
and the implementation of a program.

Data encapsulation, also called data hiding, is the technique of packing data and functions into a single component
(class) to hide implementation details of a class from the users. Users are allowed to execute only a restricted set of
operations (class methods) on the data members of the class. Therefore, encapsulation organizes the data and methods
into a structure that prevents data access by any function (or method) that is not specified in the class. This ensures the
integrity of the data contained in the object.

16

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Merits of OOP Languages
• Elimination of redundant code through inheritance (by extending existing classes).
• Higher productivity and reduced development time due to reusability of the existing modules.
• Secure programs as data cannot be modified or accessed by any code outside the class.
• Real world objects in the problem domain can be easily mapped objects in the program.
• A program can be easily divided into parts based on objects.
• The data-centered design approach captures more details of a model in a form that can be easily implemented.
• Programs designed using OOP are expandable as they can be easily upgraded from small to large systems.
• Message passing between objects simplifies the interface descriptions with external systems.
• Software complexity becomes easily manageable.
• With polymorphism, behavior of functions, operators, or objects may vary depending upon the circumstances.
• Data abstraction and encapsulation hides implementation details from the external world.
• OOP enables programmers to write easily extendable and maintainable programs. 17

• OOP supports code reusability to a great extent. © OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.
Demerits of OOP Languages

Programs written using object oriented languages have greater processing overhead as they demand more resources.
• Requires more skills to learn and implement the concepts.
• Beneficial only for large and complicated programs.
• Even an easy to use software when developed using OOP is hard to be build.
• OOP cannot work with existing systems.
• Programmers must have a good command in software engineering and programming methodology.

18

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.


Applications of OOP Languages
• Designing user interfaces such as work screens, menus, windows, and so on.
• Real-time systems • Simulation and modelling
• Compiler design • Client server system
• Object oriented databases • Object oriented distributed database
• Parallel programming • Decision control systems
• Office automation systems • Hypertext and hypermedia
• Computer-aided design (CAD) systems • Computer-aided manufacturing (CAM) systems
• Computer animation • Developing computer games
• Artificial intelligence—expert systems and neural networks
• Networks for programming routers, firewalls, and other devices
19

© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.

You might also like