0% found this document useful (0 votes)
28 views36 pages

Unit 2 Introduction

This document provides an introduction to object-oriented programming (OOP) concepts. It discusses the basic definition of a computer program and programming language. It then covers key OOP concepts like classes, objects, methods, inheritance, polymorphism, encapsulation, and abstraction. The document also discusses different programming paradigms and generations of programming languages that have evolved to support OOP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views36 pages

Unit 2 Introduction

This document provides an introduction to object-oriented programming (OOP) concepts. It discusses the basic definition of a computer program and programming language. It then covers key OOP concepts like classes, objects, methods, inheritance, polymorphism, encapsulation, and abstraction. The document also discusses different programming paradigms and generations of programming languages that have evolved to support OOP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

UNIT 2

Basic of python programming


By
K.KOWSALYADEVI
Department of CSE
Introduction to object oriented
programming (OOP)
1.1 Computer programming and
programming language
• A program is a collection of instructions that tells the
computer how to solve a particular problem.

• We have already written algorithm and pseudocode


and drawn flowcharts that gives a blueprint of the
solution.

• A programming is the process of taking an algorithm


and writing it in a particular programming language.
• A programming language is a language specially designed to express
computations that can be performed by a computer.

• It is used to create programs that control the behavior of a system, to


express algorithm, or as a mode of human communication.

• It refers to high level language such as


– BASIC (Beginner's All-purpose Symbolic Instruction Code)
– C
– C++
– COBOL (Common Business Oriented Language)
– FORTRAN (FORmula TRANslation)
– Python
– Ada
– Pascal

Each of these language has a unique set of keywords and special syntax for
organizing program instruction.
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.
 Features to write the application.
 The built-in features that support the development of software that are reliable and less
prone to crash.
 Lower development and maintenance costs.
 Stability and capability to support even more than the expected simultaneous users.
 Elasticity of a language that implies the ease with which new features (or functions) can be
added to the existing program.
 Portability.
 Better speed of development that includes the time it takes to write a code, time taken to
find a solution to the problem at hand, time taken to find the bugs, availability of
development tools, experience and skill of the programmers, and testing rules.
1.2.Generation of programming language
• In 1940s when computer were being developed, there was just
one language- machine language.

• As of now, 100s of programming languages exist in the market.

• The 5 generation of programming languages include


– machine language
– assembly language
– high-level language (3rd GL)
– very high level language (4th GL)
– 5th generation language (AI)
1.3 programming paradigm(set of ideas or
way of thinking)
• It is a fundamental style of programming that
defines how the structure and basic elements
of a computer program will be built.

• The evolution of high level programming


languages has resulted in a shift in
programming paradigm.
It is classified as:
1. monolithic programming- emphasizes on finding a solution
2. procedural programming- lays stress on algorithm
3. structured programming- focuses on modules
4. oop- emphasizes on classes and objects.
5. logic-oriented programming- focuses on goals usually
expressed in predicate calculus.
6. Rule-oriented programming- make use of “if-then-else”
rules for computation.
7. constraint-oriented programming – utilizes invariant
relationships to solve a problem.
1. monolithic programming
• Program written in this language such as Assembly
language and BASIC consists of global data and
sequential code.

• The global data can be accessed and modified from any


part of the program.

• A sequential code is one in which all instructions are


executed in the specified sequence.
– To change sequence of inst. jump statement or ‘goto’
statement are used.
• It is used only for very small and simple
applications where reusability is not a
concern.
2. procedural programming
• A program is divided into n number of subroutines that access global
data.

• To avoid repetition of code, each subroutines performs a well-defines


task.

• Service provided by another subroutine can call that subroutine.

• Using jump, goto, call instructions, the sequence of execution of


instructions can be altered.

• FORTRAN and COBOL are 2 popular procedural programming languages.


• Advantages:
- the only goal is to write correct pgm.
• -pgm were easier to write as compared to monolithic
programming.

• Disadvantages:
Procedural programming
3. structured programming
• It is referred to as modular programming .

• It is used in large programs that require a large development team to develop


different parts of the same program.

• Employs top down approach.

• Modularization makes it easier to write, debug, and understand pgm.

• It is used for large and complex program.

• C, pascal.

• Avoid use of ‘goto’ statements, instead it supports selection and repetition .


Advantage:
-each module performs a specific task, own local
data.
Disadvantage:
- it is not data centered.
-Global data is shared and may be modified.
-Main focus Is on functions
4.oop
• It is Task-based and data-based.
• All the relevant data and tasks are grouped
together in entities known as object.
1.4 Features of oop
• The oop must support mechanism to define, store, manipulate
object and allow communication between objects.
• Concepts of oop as follow:
– Classes
– Objects
– Methods
– Message passing
– Inheritance
– Polymorphism
– Containership
– Reusability
– Delegation
– Data abstraction and encapsulation
Classes
• A class is a collection of objects.
• It is a user-defined data types that behaves
same as the built-in data types.
• Classes define properties and behavior of
objects.
Objects
• Take ex.of student class, is used to create
instances known as objects.
• Every object contains some data and functions
called methods.
• These methods store data in variables and
respond to the messages that they receive
from other objects by executing their
methods(procedures)
Method and message passing
• A method is a function associated with a class.
• In oop, only methods of the class can access
and manipulate (control) the data stored in an
instance of the class.
• An object is an instance of a class which can
be uniquely identified by its name. every
object has a state which is given by the values
of its attributes at a particular time.
Inheritance
• It is a concept of OOP in which a new class is
created from an existing class.
• The new class known as subclass or derived
class.
• Inherits the attributes and behavior of the pre
existing class referred to as super class or parent
class.
• Inheritance relation is also called ‘is-a’ relation.
• It reuse the code.
Polymorphism
• It is related to methods.

• In simple words, polymorphism allows us to perform


the same action in many different ways.

• Polymorphism define methods in the child class that


have the same name as the methods in the parent
class.

• Eg. +operator.
Containership
• It is the ability of a class to contain objects of
one or more classes as member data.
• It is also called composition.
• Containership represents a ‘has-a’
relationship.
Reusability
• It means developing codes that can be reused
either in the same program or in different
programs.
• Python gives the importance to building
programs that are reusable.
• It attained through inheritance, containership
and polymorphism.
Delegation
Delegation is a design pattern in which an object, called the delegate, is responsible for
performing certain tasks on behalf of another object, called the delegator

• To provide maximum flexibility to programmers


and to allow them to generate a reusable code.

• Oop language also support delegation.

• In composition, an object can be composed of


other objects and thus, object exhibits a ‘has-
a’ relationship.
Data Abstraction and encapsulation
• Data abstraction refers to the process by
which data and functions are defined that only
essential details are revealed and
implementation details are hidden.

• Main focus is to separate the interface and the


implementation of a program.
Encapsulation
• Data encapsulation also called data hiding.
• Encapsulation is a mechanism of wrapping the
data (variables) and code acting on the data
(methods) together as a single unit.
• In Python, there are three types of encapsulation:

Private access
Protected access
Public access
Application of OOP

You might also like