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

OOSD Unit 1 1

The document discusses object-oriented programming concepts including procedural programming, structure programming, and object-oriented programming. It defines objects and classes, and describes key object-oriented programming concepts like abstraction, encapsulation, inheritance, and polymorphism.

Uploaded by

kimmisiingh04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

OOSD Unit 1 1

The document discusses object-oriented programming concepts including procedural programming, structure programming, and object-oriented programming. It defines objects and classes, and describes key object-oriented programming concepts like abstraction, encapsulation, inheritance, and polymorphism.

Uploaded by

kimmisiingh04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

UNIT-1

Part-1: Object-Oriented Programming Concepts


INTRODUCTION TO OBJECT ORIENTATION:

There are mainly three categories : Procedure Oriented, Structure Oriented and Object Oriented

Procedure Oriented:

 Procedural Programming can be defined as a programming model which is g, based upon


the concept of calling procedure. Procedures, also known as routines, subroutines or
functions, simply consist of a series of computational steps to be carried out
 Program always organize in the form of subroutines.
 Control always jump threw goto statement & call subroutines.
 Subroutines are abstracted to avoid repetition.
 It is suitable for medium size software applications.
 Programs are difficult to maintain and enhance.
 Ex. COBOL, FORTRAN etc.

Structure Oriented:

 Structure program consist several modules. Each module has set of related functions.
 It focuses on algorithm rather than data.
 Program divided into independent procedure & procedures have their own local data.
 We can also pass parameters in procedure.
 There is one entry and one exit point.
 It uses sequence structure, decision structure and loop structure.
 There may be user defined data type in structure programming.
 Maintenance is complex & costly.
 Ex. PASCAL, C etc.

What is OOP?

 Object oriented programming is the principle of design and development of programs


using modular approach.
 OOP approach provides advantages in creation and development of software for real
life application.
 The basic element of OOP is the data(in form of attributes) and code in form of methods..
 The programs are built by combining data and functions that operate on the data.
 Some of the OOP’s languages are C++ ,java, C#, smalltalk, Perl and Python.
 OOP is a concept that combines both the data and functions that operate on that data into
a single unit called the object.
 An object is a collection of set of data known as member data and the functions that

Axis Institute of Technology & Management, Kanpur Page 1


operate on these data known as member function.
 Class is the major concept that plays important role in this approach. Class is a template
that represents a group of objects which share common properties and relationships.
Procedural Oriented Programming Object-Oriented Programming

In procedural programming, the program is divided In object-oriented programming, the program is


into small parts called functions. divided into small parts called objects.

Procedural programming follows a top-down Object-oriented programming follows a bottom-


approach. up approach.

There is no access specifier in procedural Object-oriented programming has access


programming. specifiers like private, public, protected, etc.

Adding new data and functions is not easy. Adding new data and function is easy.

Procedural programming does not have any proper Object-oriented programming provides data
way of hiding data so it is less secure. hiding so it is more secure.

In procedural programming, overloading is not Overloading is possible in object-oriented


possible. programming.

In procedural programming, there is no concept of In object-oriented programming, the concept of


data hiding and inheritance. data hiding and inheritance is used.

In procedural programming, the function is more In object-oriented programming, data is more


important than the data. important than function.

Object-oriented programming is based on the real


Procedural programming is based on the unreal world.
world.

Procedural programming is used for designing Object-oriented programming is used for


medium-sized programs. designing large and complex programs.

Procedural programming uses the concept of Object-oriented programming uses the concept of
procedure abstraction. data abstraction.

Code reusability present in object-oriented


Code reusability absent in procedural programming,
programming.

Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.

Axis Institute of Technology & Management, Kanpur Page 2


Building blocks of OOP: Classes and Objects

Class has

 Set of attributes or properties that describes every object


 Set of behavior or actions that every object can perform

A class is a set of variables (to represent its attributes)and functions (to describe its behavior)
that act on its variables.

Object has

 Set of data (value for each of its attribute)


 Set of actions that it can perform
 An identity

Object is an instance of a class that holds data (values) in its variables. Data can be accessed by
its functions.

Real Life Examples of Class and Objects with its attributes and behaviour

Axis Institute of Technology & Management, Kanpur Page 3


What Is an Object?

Objects are key to understanding object-oriented technology. Look around right now and you'll
find many examples of real-world objects: your dog, your desk, your television set, your bicycle.

Real-world objects share two characteristics: They all have state and behavior. Dogs have state
(name, color, and breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also
have state (current gear, current pedal cadence, and current speed) and behavior (changing gear,
changing pedal cadence, applying brakes). Identifying the state and behavior for real-world
objects is a great way to begin thinking in terms of object-oriented programming.

Software objects are conceptually similar to real-world objects: they too consist of state and
related behavior. An object stores its state in fields (variables in some programming languages)
and exposes its behavior through methods (functions in some programming languages). Methods
operate on an object's internal state and serve as the primary mechanism for object-to-object
communication. Hiding internal state and requiring all interaction to be performed through an
object's methods is known as data encapsulation— a fundamental principle of object-oriented
programming.

What Is a Class?

In the real world, you'll often find many individual objects all of the same kind. There may be
thousands of other bicycles in existence, all of the same make and model. Each bicycle was built
from the same set of blueprints and therefore contains the same components. In object-oriented
terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is
the blueprint from which individual objects are created.

Axis Institute of Technology & Management, Kanpur Page 4


OOP concepts:

 Abstraction
 Encapsulation
 Inheritance
 Polymorphism

 What Is Abstraction(Information Hiding)?

 Extracting essential properties and behavior of an entity


 Class represents such an abstraction and is commonly referred to as an abstract data type

Abstraction is the essential element of Object Oriented programming (OOP). It refers to the
representation of essential features without including the background details or explanations or
implementations.

 Problem

(Processing)

Model

 What Is Encapsulation?

 Binding together the data and functions that manipulate them


 Mechanism by which we combine data and the functions that manipulate the data into
one unit
 Objects & Classes enforce encapsulation

Axis Institute of Technology & Management, Kanpur Page 5


 The wrapping of data and functions into a single unit called class is known as
encapsulation. Accessing to the code and data inside the wrapper is tightly controlled
through a well-defined interface.

 Properties of Encapsulation

Data Protection Information hiding

1. Data Protection: It provides data integrity and maintains the consistency of the object's
state.
2. Information hiding: Encapsulation hides the internal details of an object, protecting the data
from unauthorized access or modification.

 What Is Inheritance?

 Create new classes (derived classes) from existing classes (base classes)
 The derived class inherits the variables and functions of the base class and adds
additional ones!
 Provides the ability to re-use existing code
 The mechanism of deriving a new class from an old class is called inheritance or
derivation.
 The different types of inheritance are single, hierarchical, multiple and multilevel
inheritance.
 The derived class is also called as Child Class and the base class is also called as Parent
class.
 Sub Class- It is the class that inherits the properties from another class
 Super Class- It is the class whose properties are being inherited.

Axis Institute of Technology & Management, Kanpur Page 6


Different kinds of objects often have a certain amount in common with each other. Mountain
bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current
speed, current pedal cadence, and current gear). Yet each also defines additional features that
make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have
drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear
ratio.

Object-oriented programming allows classes to inherit commonly used state and behavior from
other classes. In this example, Bicycle now becomes the superclass of Mountain Bike, Road
Bike, and Tandem Bike.

Axis Institute of Technology & Management, Kanpur Page 7


 What Is Polymorphism?

Polymorphism is another important OOP concept; Polymorphism is a Greek term which means
the ability to take more than one form.

1. Compile time Polymorphism: This type of polymorphism is achieved by function


overloading or operator overloading.

 Operator Overloading: The process of making an operator exhibit different behaviors in


different instances is known as operator overloading.
 Function Overloading: Function overloading is using a single function name to perform
different types of tasks. Polymorphism is extensively used in implementing inheritance.
2. Run time Polymorphism In contrast, with compile time polymorphism, the compiler
determines which function call to bind to the object after deducing it at runtime.

• Function Overriding:Function Overriding occurs when a derived class has a definition for
one of the member functions of the base class. That base function is said to be overridden.
 Virtual Function:A virtual function is a member function that is declared in the base class
using the keyword virtual and is re-defined (Overridden) in the derived class.
Some Key Points About Virtual Functions:
 Virtual functions are Dynamic in nature.
 They are defined by inserting the keyword “virtual” inside a base class and are always
declared with a base class and overridden in a child class
 A virtual function is called during Runtime

Axis Institute of Technology & Management, Kanpur Page 8


For example, a dog's sense of smell () is polymorphic which has many forms such as If the dog
smells () a cat, it will bark and run after it. If the dog smells () its food, it will salivate and run to its
bowl. The same sense of smell () in both situations doing different job depending on what is being
smelled (), i.e. the type of data operated upon by the dog's nose.

Advantages of OOP:

 Reusability: It means reusing the same code again and again rather than building them.
OOP allows developers to create code that can be reused in different parts of an
application. This makes development faster and more efficient because developers do not
have to write new code from scratch each time they need to create a new feature.
 Modularity: OOP allows developers to break down complex systems into smaller, more
manageable modules. This makes it easier to develop, test, and maintain code because
changes made to one module do not affect other parts of the system.
 Data redundancy: OOP allow similar functionality in multiple classes to a user i.e., user
can write common definition and inherit them.
 Code Maintenance: Changes and bug fixes can be made to specific objects or classes
without affecting other parts of the system, reducing errors and improving debugging.
 Security: OOPs protects data integrity and privacy by restricting direct access and
allowing controlled access through methods.
 Design Benefits: It is to design better code with fewer flaws.
 Better Productivity: It leads to more work done, finishing a better program having more
inbuilt features and easy writing ,reading and maintenance.
 Easily Upgradable & Scalable: OOP enables easy addition and modification of features
without impacting the entire codebase. OOP makes it easier to scale a program to handle an
increasing amount of work or data.

Disadvantages of OOP:

Axis Institute of Technology & Management, Kanpur Page 9


Object Identity-

Generosity:


Generosity is a technique for defining software components that have more than one
interpretation depending on the data types of parameters.
 It allows the declaration of data items without specifying their exact data type.
 Such unknown data types (generic data type) are resolved at the time of their usage based
on the data type of parameters during a function call.
 It is a process that allows a function or a class to work with different-different data types.
That type of function is called Template Function.
Model-
A model is a simplification of reality. A model provides the blueprints of a system. Models may
encompass detailed plans, as well as more general plans. A model may be structural, emphasizing
the organization of the system, or it may be behavioral, emphasizing the dynamics of the system.
We build model so that we can better understand system we are developing.

IMPORTANCE OF MODELING:

Modeling is a proven and well-accepted engineering technique. We build architectural models of


houses and high rises to help their users visualize the final product. We may even build
mathematical models in order to analyze the effects of winds or earthquakes on our buildings.

 Testing a physical entity before building it. Both physical models and computer models
are usually cheaper than building a complete system and enable early correction of flaws.
 Communication with customers. Architects and product designers build models to show
their customers. Mock-ups are demonstration products that imitate some or all of the
external behaviour of a system.
 Visualization. Storyboards of movies, television shows, and advertisements let writers see
how their ideas flow. They can modify awkward transitions, dangling ends, and
unnecessary segments before detailed writing begins.
 Reduction of complexity. Perhaps the main reason for modelling, which incorporates all
the previous reasons, is to deal with systems that are too complex to understand directly.
The human mind can cope with only a limited amount of information at one time. Models
reduce complexity by separating out a small number of important things to deal with at a
time.
Through modeling we achieve four aims:

 Models help us to visualize a system as it is or as we want it to be.


 Models permit us to specify the structure or behavior of a system.
 Models give us a template that guides us in constructing a system.
 Models document the decisions we have made.

Axis Institute of Technology & Management, Kanpur Page 10


PRINCIPLES OF MODELING:

1. The choice of what models to create has a profound influence on how a problem is
attacked and how a solution is shaped.

If you build a system through the eyes of a database developer, you will likely focus on entity-
relationship models that push behavior into triggers and stored procedures. If you build a system
through the eyes of a structured analyst, you will likely end up with models that are algorithmic-
centric, with data flowing from process to process. If you build a system through the eyes of an
object-oriented developer, you'll end up with a system whose architecture is centered around a
sea of classes and the patterns of interaction that direct how those classes work together.

2. Every model may be expressed at different levels of precision.

A quick and simple executable model of the user interface is exactly what you need; at other
times, you have to get down and dirty with the bits, such as when you are specifying cross-
system interfaces or wrestling with networking bottlenecks. In any case, the best kinds of models
are those that let you choose your degree of detail, depending on who is doing the viewing and
why they need to view it. An analyst or an end user will want to focus on issues of what; a
developer will want to focus on issues of how. Both of these stakeholders will want to visualize a
system at different levels of detail at different times.

3. The best models are connected to reality.

Achilles heel of structured analysis techniques is the fact that there is a basic disconnect between
its analysis model and the system's design model. Failing to bridge this chasm causes the system
as conceived and the system as built to diverge over time. In object-oriented systems, it is
possible to connect all the nearly independent views of a system into one semantic whole.

4. No single model is sufficient. Every nontrivial system is best approached through a


small set of nearly independent models.

The operative phrase here is "nearly independent." In this context, it means having models that
can be built and studied separately but that are still interrelated. As in the case of a building, you
can study electrical plans in isolation, but you can also see their mapping to the floor plan and
perhaps even their interaction with the routing of pipes in the plumbing plan.

OBJECT ORIENTED MODELING:

There are several ways to approach a model. The two most common ways are from an
algorithmic perspective and from an object-oriented perspective.

 The Algorithmic Approach- also called as the traditional view of software


development takes an algorithmic perspective. In this approach, the main building block

Axis Institute of Technology & Management, Kanpur Page 11


of all software is the procedure or function. This view leads developers to focus on issues
of control and the decomposition of larger algorithms into smaller ones. There's nothing
inherently evil about such a point of view except that it tends to yield brittle systems. As
requirements change (and they will) and the system grows (and it will), systems built
with an algorithmic focus turn out to be very hard to maintain.
 The Object-Oriented Approach- also called as the contemporary view of software
development takes an object-oriented perspective. In this approach, the main building block of
all software systems is the object or class. Simply put, an object is a thing, generally drawn from
the vocabulary of the problem space or the solution space; a class is a description of a set of
common objects. Every object has identity (you can name it or otherwise distinguish it from
other objects), state (there's generally some data associated with it), and behavior (you can do
things to the object, and it can do things to other objects, as well).The object-oriented approach
to software development is decidedly a part of the mainstream simply because it has proven to be
of value in building systems in all sorts of problem domains and encompassing all degrees of
size and complexity.
Types of Object Oriented Models-

1. Object Model
 It represents the static structure of the application.
 It specifies to whom it happens to.
 Operations in an object model correspond to events in dynamic models and functions in
functional models.
 It is represented using class diagrams.
2. Dynamic Model
 It represents the essential behavior of the application.
 It specifies when it happens.
 Dynamic model describes the control structure of the objects. It defines decisions which are
dependents of object values and which can cause action to change object values and invoke
their functions.
 It is represented using state diagrams.
3. Functional Model
 It represents what the application does and not how it does.
 It specifies what happens.
 It describes functions to be invoked by operations in object model and actions in dynamic
models.
 It is represented using data flow diagrams.

Axis Institute of Technology & Management, Kanpur Page 12

You might also like