Você está na página 1de 48

Evolution of programming methodologies.

Programming Paradigm

Paradigm means methodology. A programming paradigm is a fundamental style of computer programming or the programming technique. Examples: Procedural, object-oriented.

Types of programming paradigms


Monolithic programming Structured Programming Procedural programming. Object-oriented Programming

Monolithic programming
Monolithic Programming indicates the program which contain a single function for the large program. Monolithic programming will not divide the program And it is a single thread of execution. When the program size increases it leads inconvenience and difficult to maintain. It is suitable for developing small and simple applications Ex:BASIC

Disadvantages of monolithic programming:


1. Difficult to check error on large programs. 2. Difficult to maintain. 3. Code can be specific to a particular problem. i.e. it can not be reused.

Structured Programming

Here, where programming tasks can be split into smaller sections known as functions or subroutines, which can be called whenever they are required. Structured programming is often (but not always) associated with a top-down approach to design. Structured or procedural programming attempts to divide the problem into smaller blocks or procedures which interact with other. The aim is to clearly define the structure of the program before writing program code. Examples: Pascal , Ada,C

Procedure-Oriented Programming
Programming using high level languages such as COBOL,FORTRAN is known as POP The problem is viewed as a sequence of things to be done. The primary focus is on functions. Procedure-oriented programming basically consists of writing a list of instructions for the computer to follow and organizing these instructions into groups known as functions

Typical structure of procedure-oriented program


Main Program

Function-1

Function-2

Function-3

Function-4

Function-5

Function-6

Function-7

Function-8

Characteristics
Emphasis is on doing things (algorithms) Larger programs r divided into smaller programs known as functions Most of the functions share global data Data move openly around the system from function to function Functions transform data from one form to another Employs top-down approach in prog. Design Main task is taken up first and is divided into smaller logically independent components which in turn accomplish the specified sub tasks

Relationship of data and functions in procedural programming


Global Data Global Data

Function-1

Function-2

Function-3

Local Data

Local Data

Local Data

Drawbacks

Global data are more vulnerable to an inadvertent change by a function.

In a large prog. it is very difficult to identify what data is used by which function.

It does not model real world problems very well Complexity increases as the programs grow larger and complex Data is not secured as it freely moves from one procedure to another.

Object-Oriented Programming
OOP treat data as a critical element in the program development and does not allow it to flow freely around the system. It ties data more closely to the functions that operate on it, and protects it from accidental modification from outside functions. OOP allows decomposition of a problem into a number of entities called objects and then build data functions around these objects The data of an object can be accessed only by the functions associated with that object.Functions of one object can access the functions of another objects.

Organization of data and functions in OOP


Object A Data Object B Data

Communication
Functions Functions

Object C Data Functions

Characteristics of Object-Oriented Programming

Emphasis is on data rather than procedure. Programs are divided into objects. Data structures are designed such that they characterize the objects. Functions that operate on the data of an object are tied together in the data structure. Data is hidden and can not be accessed by external functions.

Objects may communicate with each other through functions. New data and functions can be added easily whenever necessary. Follows bottom-up approach in program design.

Depending upon object features supported oop language divide into two 1. Object based programming language 2. Object oriented programming language Object based language support encapsulation and object identity without supporting polymorphism,inheritance etc. Object based language= encapsulation + object identity Object oriented supports all the features of object based and inheritance and polymorphism Object oriented language = object based features+inheritance+polymorphism

Basic Concepts of Object-Oriented Programming

Object-Oriented Programming

Definition: It is an approach that provides a way of modularizing programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand. Thus the object is considered to be a

partitioned area of computer memory that stores data and set of operations that can access that data.

Data Members

Member Functions

Outside World

Basic representation of an object

Basic Concepts of Object-Oriented Programming


Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism Dynamic Binding Message Passing Extensibility Reusability modularity

Objects
Objects are the basic run-time entities in an objectoriented system. They may represent a person, a place, a bank account, etc. Objects take up space in the memory and have an associated address like a structure in C. When a program is executed, the objects interact by sending messages to one another.

Every object will have data structures called attributes and behavior called operations

object Name

: Account attributes : AccountNumber, AccountType, Balance behavior : Deposit, Withdraw, Enquire

Account Acc.No Acc.Type Name Bal Deposit( ) Withdraw( ) Enquire( ) Acc.No Acc.Type Name Bal

Account Acc.No Acc.Type Name Bal

Deposit( )
Withdraw( ) Different styles of representing the account object

Enquire( )

Object : CUSTOMER DATA AC No. Name of AC Holder Address

Object : ACCOUNT DATA AC No. AC Balance Type of Account

FUNCTIONS Deposit Withdrawal AC Balance Display

FUNCTIONS Account Balance

Classes
Classes are user-defined data types. Objects with same data structure(attributes) and behaviour(operation) are grouped into class
Objects are variables of the type class. Once a class has been defined, we can create any number of objects belonging to that class. Each object is associated with the data of type class with which they are created.

Objects with the same data structure (attributes) and behavior (operations) are grouped into class If fruit has been defined as a class, then the statement

fruit mango; will create an object mango belonging to the class fruit.

Data Abstraction and Encapsulation


o

The wrapping up of data and functions into a single unit is known as encapsulation. 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 objects data and the program. This insulation of the data from direct access by the program is called data hiding or information hiding.

Eg: In company, departments access and work with their data on their own Cannot access data of other department directly Req. is made for the data and data is handed over by the members of the req. dept.

The attributes wrapped in the classes are called data members and the functions that operate on these data are called methods or member functions. Since the classes use the concept of data abstraction, they are known as Abstracted Data Types (ADT).

Abstraction

Abstraction refers to the act of representing essential features without including the background details or explanations

Driving a car

know gear handling etc Dont know wiring, motor working etc

Inheritance
o

Inheritance is the process by which objects of one class acquire the properties of objects of another class. It supports the concept of hierarchical classification. Each derived class shares common characteristics with the class from which it is derived.

Parent

Parent features

Base Class

Child

Parent features Childs features

Derived Class

Bird Attributes: Feathers Lay eggs

Flying Bird Attributes: -----------------------

Non-flying Bird

Attributes: -----------------------

Robin Attributes: -----------------------

Swallow Attributes: -----------------------

Penguin Attributes: -----------------------

Kiwi Attributes: -----------------------

Inheritance provides the idea of reusability.


o

We can add additional features to an existing class without modifying it. By deriving new class from existing one. The new class will have the combined features of both the classes.

Generalization starts from the bottom goes to top Specialization starts at the top and moves down to the bottom Eg: Person->employee->manager

Specialization

Generalization

Vehicle represents all of the generic attributes and methods of a vehicle.

Vehicle

Vehicle is the parent class.

is-a relationship

Car and Truck are child classes of Vehicle.

Car

Truck

Car and Truck are Specialized versions of a Vehicle.

Diagram

Cirlce

Triangle

Square

class diagram has an attribute called angle rep. angle inside diagram, shape each subclass automatically inherits all the properties such as angle,shape

Polymorphism

- ability to take more than one form

An operation may exhibit different behaviors in different instances. The behavior depends upon the types of data used in the operation. For e.g., consider the operation of addition of two numbers,the operation will generate a sum. If the operands are strings,then the operation would produce a third string by concatenation.
add( 3, 5) gives 8
Add(hello, -world) gives hello-world

Overloading:

Overloading is one type of Polymorphism. It allows an object to have different meanings, depending on its context. When an existing operator or function begins to operate on new data type, or class, it is understood to be overloaded.

o
o

The process of making an operator to exhibit different behaviours in different instances is known as operator overloading. Using a single function name to perform different types of tasks is known as function overloading.
add( 3, 5) gives 8 Add(hello, -world) gives hello-world

Dynamic Binding

Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding ( late binding ) means that the code associated with a given procedure call is not known until the time of the call at run-time. It is associated with polymorphism and inheritance.

Message Passing

o o

It is a process of invoking an operation on an object.in response to a message the corresponding method is executed in the object An oop consists of a set of objects that communicate with each other. Oop involves the following steps:
o o o

Creating classes that define objects and their behaviour. Creating objects from class definitions. Establishing communication among objects.

Objects communicate with one another by sending and receiving information.

A message for an object is a request for execution of a procedure. The receiving object will invoke a function and generates results. Message passing involves specifying:
o

o
o

The name of the Object. The name of the Function. The information to be send.

Reusability

This term refers to the ability for multiple programmers to use the same written and debugged existing class of data. This is a time saving device and adds code efficiency to the language. Additionally, the programmer can incorporate new features to the existing class, further developing the application and allowing users to achieve increased performance. This time saving feature optimizes code, helps in gaining secured applications and facilitates easier maintenance on the application.

extensibility

Is a feature which allows the extension of the functionality of the existing software components.in c++it is achieved through abstract class and inheritance

Modularity

The act of partitioning a program into individual components is called modularity. It gives the following benefits. l It reduces its complexity to some extent. l It creates a number of well-defined, documented boundaries within the program. Module is a separate unit in itself. It can be compiled independently though it has links with other modules. Modules work quite closely in order to achieve the programs goal.

eliminate redundant code and extend the use of existing classes. We can build programs from the standard working module, no need of starting from the scratch.
Inheritance

Benefits of OOP

Data hiding helps the programmer to build secure programs that can not be invaded by code in other parts of the program.

Multiple

instances of an objects can co-exists with out any interference. It is easy to partition the work in a project based on objects.

Object-oriented system can be easily upgraded from small to large systems. Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler. Software complexity can be easily managed.

Você também pode gostar