Professional Documents
Culture Documents
Unit-1 (Part-A) Notes of OOPS by Updesh Kumar - Updated
Unit-1 (Part-A) Notes of OOPS by Updesh Kumar - Updated
4
Differences
Procedural Programming Object Oriented Programming
Large programs are divided into Programs are divided into
smaller programs known as objects
functions
5
Basic Concepts of OOP’s
The following are the major characteristics of OOP’s:
6
An object can be defined as a data field that has unique attributes and behavior.
An object is an element (or instance) of a class; objects have the behaviors of their class.
An object is a data type that can take in collections of key-value pairs.
Objects
Objects are basic building blocks for designing
programs.
An object is a collection of data members and
For example, suppose Bicycle is a class then MountainBicycle , SportsBicycle , TouringBicycle , etc can be
considered as objects of the class.
associated member functions.
An object may represent a person, place or a table
of data. Pankaj
Classes
The objects can be made user defined data types
with the help of a class.
A class is a collection of objects that have
identical properties, common behavior and
shared relationship.
Once class is defined, any number of objects of
that class is created.
Classes are user defined data types.
A class can hold both data and functions.
For example: Planets, sun, moon
are member of class solar system.
Class Name: Solar System 8
Data Abstraction,
Encapsulation & Data Hiding
Data Abstraction
Data Abstraction refers to the process of representing
essential features without including background details
or explanations.
Data Encapsulation:
◦ The wrapping of data and functions into a single unit
(class) is called data encapsulation.
◦ Data encapsulation enables data hiding and information
hiding.
◦ Data hiding is a method used in object oriented
programming to hide information within
computer code.
9
Inheritance
Inheritance is the process by which one object
can acquire and use the properties of another
object.
The existing class is known as base class or super class.
The new class is known as derived class or sub class.
The derived class shares some of the properties of the base
class. Therefore a code from a base class can be
reused by a derived class.
So, Inheritance allows a class (subclass) to acquire the properties
and behavior of another class (super-class). It helps to reuse,
customize and enhance the existing code.
10
Overloading
Overloading allows objects to have different
meaning depending upon context.
There are two types of overloading viz.
o Operator Overloading
o Function Overloading
When an existing operator operates on new data
type is called operator overloading.
Function overloading means two or more
function have same name, but differ in the
number of arguments or data type of arguments.
11
Polymorphism
The ability of an operator and function to take
multiple forms is known as Polymorphism.
The different types of polymorphism are operator
overloading and function overloading.
12
Dynamic binding & Message
Passing Binding refers to the linking of a procedure call to the code to be executed in
response tothe call. Dynamic binding also known as late binding means that
the code associated with agiven procedure call is not known until the time of
call at run time.
Dynamic binding:
◦ Binding is the process of connecting one program to another.
◦ Dynamic binding is the process of linking the procedure call
to a specific sequence of code or function at run time or
during the execution of the program.
Message Passing:
◦ In OOP’s, processing is done by sending message to objects.
◦ A message for an object is request for execution of
procedure.
◦ Message passing involves specifying the name of the object,
the name of the function (message) and the information to be
sent.
13
Advantage of OOP’s
The programs are modularized based on the principles of classes
and objects.
Linking code & object allows related objects to share common
code. This reduces code duplication and code reusability.
Creation and implementation of OOP code is easy and reduces
software development time.
The concept of data abstraction separates object specification and
object implementation.
Data encapsulated along with functions. Therefore external non-
member function cannot access or modify data, thus proving data
security.
Easier to develop complex software, because complexity can be
minimized through inheritance.
OOP can communicate through message passing which makes
14
Disadvantage of OOP’s
Larger program size: OOP’s typically involves more lines
of code than procedural programs.
Slower Programs: OOP’s typically slower than procedure
based programs, as they typically require more instructions
to be executed.
Not suitable for all types of programs.
To convert a real world problem into an object oriented
model is difficult.
OOP’s software development, debugging and testing tools
are not standardized.
Polymorphism and dynamic binding also requires
processing time, due to overload of function calls during
run time.
15
Application of OOP’s
Computer graphics applications.
CAD/CAM software
Object-oriented database.
User-Interface design such as windows
Real-time systems.
Simulation and Modeling
Artificial intelligence and expert systems.
Client-Server Systems.
16
Important Questions
2 Marks Question:\
1. Explain: Classes, Objects, Data Abstraction, Data Encapsulation,
Inheritance, and Polymorphism.
What is Base class and derived class?
5 Marks Question:
1. Distinguish between procedural and object oriented programming.
2. Explain the characteristics of OOP’s.
3. Briefly explain the basic concepts of OOP’s.
4. Explain the advantages of OOP’s.
5. Mention disadvantages of OOP’s.
6. Write the applications of OOP’s.
17
Please go on next PPT or Slide
Thank you
18
Genericity is one of the most powerful means for obtaining flexibility in C++ programming
languages. Genericity has different forms and the choice of it has a considerable impact
on expressiveness, modularity, static checkability and efficiency properties of programs.
Generosity:
It is a quality that's a lot like unselfishness. Someone showing generosity is happy to give time,
money, food, or kindness to people in need.. When you show generosity, you might give away
things or money or put others before yourself. But generosity is about more than cash and stuff.
As a developer working on a single project for days, weeks and possibly even months. It gets
boring and your mind will focus on the project at hand, forgetting other things that developers
might encounter.
By looking at what troubles other developers, you learn to maintain your other skillsets while
working on your current project. For example, I will answer questions about C++ or PHP even
though I rarely use them anymore, simply to keep reminding myself that I know those
languages. It will refresh my memory.
It is also useful for developers to learn how to teach their skills to others, which is practical when
working in teams.
Finally, there are always topics that developers don't know any answer for, so they follow it and
wait for someone else to come up with a solution. And then they consider that solution, try and
see if it would work and maybe see if it can be improved.
But developers aren't just helping others. They're helping themselves too!
Generosity reduces stress, supports one's immune system and enhances one's sense of
purpose. So what is it about generosity that makes it so vital to a happy and healthy life.
Generosity/Template: – It is a process that allows a function or a class to work with different data
types (That type of function is called template function).
Generosity is a technique for defining software components that have more than one interpretation
depending on the data type of parameters. The unknown data types are resolved at the time of
their usage based on the data type of parameters.
Object-oriented modeling (OOM) is an approach to model an
application that is used at the beginning of the software life cycle.
Importance of Modelling: Modeling can help the development team better visualize the plan
of their system and allow them to develop more rapidly by helping them build the right thing. The
more complex your project, the more likely it is that you will fail or that you will build the wrong
thing if you do on modeling at all
The choice of model is important. The choice of what models to create has a profound influence
on how a problem is attacked and how a solution is shaped.
Unified Modeling Language (UML) is a general purpose modelling language. The main
aim of UML is to define a standard way to visualize the way a system has been designed. It is quite
similar to blueprints used in other fields of engineering.
UML is not a programming language, it is rather a visual language. We use UML diagrams to portray
the behavior and structure of a system. UML helps software engineers, businessmen and system
architects with modelling, design and analysis. The Object Management Group (OMG) adopted Unified
Modelling Language as a standard in 1997.
Need:
Complex applications need collaboration and planning from multiple teams and hence require a
clear and concise way to communicate amongst them.
Businessmen do not understand code. So UML becomes essential to communicate with non
programmers essential requirements, functionalities and processes of the system.
A lot of time is saved down the line when teams are able to visualize processes, user interactions
and static structure of the system.
UML is linked with object oriented design and analysis. UML makes the use of elements and forms
associations between them to form diagrams. Diagrams in UML can be broadly classified as:
2. Behavior Diagrams – Capture dynamic aspects or behavior of the system. Behavior diagrams
include: Use Case Diagrams, State Diagrams, Activity Diagrams and Interaction Diagrams.
The image below shows the hierarchy of diagrams according to UML 2.2
Object Oriented Concepts Used in UML –
1. Class – A class defines the blue print i.e. structure and functions of an object.
2. Objects – Objects help us to decompose large systems and help us to modularize our system.
Modularity helps to divide our system into understandable components so that we can build our
system piece by piece. An object is the fundamental unit (building block) of a system which is
used to depict an entity.
3. Inheritance – Inheritance is a mechanism by which child classes inherit the properties of their
parent classes.
5. Encapsulation – Binding data together and protecting it from the outer world is referred to as
encapsulation.
6. Polymorphism – Mechanism by which functions or entities are able to exist in different forms.
1. Class Diagram – The most widely use UML diagram is the class diagram. It is the building block
of all object oriented software systems. We use class diagrams to depict the static structure of a
system by showing system’s classes,their methods and attributes. Class diagrams also help us
identify relationship between different classes or objects.
2. Composite Structure Diagram – We use composite structure diagrams to represent the internal
structure of a class and its interaction points with other parts of the system. A composite
structure diagram represents relationship between parts and their configuration which
determine how the classifier (class, a component, or a deployment node) behaves. They
represent internal structure of a structured classifier making the use of parts, ports, and
connectors. We can also model collaborations using composite structure diagrams. They are
similar to class diagrams except they represent individual parts in detail as compared to the
entire class.
4. Component Diagram – Component diagrams are used to represent the how the physical
components in a system have been organized. We use them for modelling implementation
details. Component Diagrams depict the structural relationship between software system
elements and help us in understanding if functional requirements have been covered by
planned development. Component Diagrams become essential to use when we design and build
complex systems. Interfaces are used by components of the system to communicate with each
other.
5. Deployment Diagram – Deployment Diagrams are used to represent system hardware and its
software.It tells us what hardware components exist and what software components run on
them.
6. Package Diagram – We use Package Diagrams to depict how packages and their elements have
been organized. A package diagram simply shows us the dependencies between different
packages and internal composition of packages. Packages help us to organise UML diagrams into
meaningful groups and make the diagram easy to understand. They are primarily used to
organise class and use case diagrams.
Behavior Diagrams –
1. State Machine Diagrams – A state diagram is used to represent the condition of the system or
part of the system at finite instances of time. It’s a behavioral diagram and it represents the
behavior using finite state transitions. State diagrams are also referred to as State
machines and State-chart Diagrams . These terms are often used interchangeably.So simply, a
state diagram is used to model the dynamic behavior of a class in response to time and changing
external stimuli.
2. Activity Diagrams – We use Activity Diagrams to illustrate the flow of control in a system. We
can also use an activity diagram to refer to the steps involved in the execution of a use case. We
model sequential and concurrent activities using activity diagrams. So, we basically depict
workflows visually using an activity diagram.An activity diagram focuses on condition of flow
and the sequence in which it happens. We describe or depict what causes a particular event
using an activity diagram.
3. Use Case Diagrams – Use Case Diagrams are used to depict the functionality of a system or a
part of a system. They are widely used to illustrate the functional requirements of the system
and its interaction with external agents(actors). A use case is basically a diagram representing
different scenarios where the system can be used. A use case diagram gives us a high level view
of what the system or a part of the system does without going into implementation details.
6. Timing Diagram – Timing Diagram are a special form of Sequence diagrams which are used to
depict the behavior of objects over a time frame. We use them to show time and duration
constraints which govern changes in states and behavior of objects.
A Conceptual Model:
A conceptual model of the language underlines the three major elements:
• The Rules
Building Blocks:
The vocabulary of the UML encompasses three kinds of building blocks:
1. Things:
Things are the abstractions that are first-class citizens in a model; relationships tie these things
together; diagrams group interesting collections of things.
There are 4 kinds of things in the UML:
1. Structural things
2. Behavioral things
3. Grouping things
4. Annotational things : Annotational things are the explanatory parts of UML models. These
are the comments you may apply to describe, illuminate, and remark about any element in a model.
2- Relationships:
There are 4 kinds of relationships in the UML:
1. Dependency
2. Association
3. Generalization
4. Realization
These relationships are the basic relational building blocks of the UML.
32. Diagrams:
It is the graphical presentation of a set of elements. It is rendered as a connected graph of
vertices (things) and arcs (relationships).
1. Class diagram
2. Object diagram
4. Sequence diagram
5. Collaboration diagram
7. Activity diagram
8. Component diagram
9. Deployment diagram
Rules:
The UML has a number of rules that specify what a well-formed model should look like. A well-formed
model is one that is semantically self-consistent and in harmony with all its related models.
The UML has semantic rules for:
Common Mechanisms:
The UML is made simpler by the four common mechanisms. They are as follows:
1. Specifications
In UML, behind each graphical notation, there is a textual statement denoting the syntax and semantics.
These are the specifications. The specifications provide a semantic backplane that contains all the parts
of a system and the relationship among the different paths.
2. Adornments
Each element in UML has a unique graphical notation. Besides, there are notations to represent the
important aspects of an element like name, scope, visibility, etc.
3. Common Divisions
Object-oriented systems can be divided in many ways. The two common ways of division are −
Division of classes and objects − A class is an abstraction of a group of similar objects. An object
is the concrete instance that has actual existence in the system.
Division of Interface and Implementation − An interface defines the rules for interaction.
Implementation is the concrete realization of the rules defined in the interface.
4. Extensibility Mechanisms
UML is an open-ended language. It is possible to extend the capabilities of UML in a controlled manner
to suit the requirements of a system. The extensibility mechanisms are −
Stereotypes − It extends the vocabulary of the UML, through which new building blocks can be
created out of existing ones.
UML Stereotype
Stereotype is a profile class which defines how an existing metaclass may be extended as part of
a profile. It enables the use of a platform or domain specific terminology or notation in place of,
or in addition to, the ones used for the extended metaclass.
A stereotype cannot be used by itself, but must always be used with one of the metaclasses
it extends. Stereotype cannot be extended by another stereotype.
A stereotype uses the same notation as a class, with the keyword «stereotype» shown before or
above the name of the stereotype. Stereotype names should not clash with keyword names for
the extended model element.
Here Device extended by Server stereotype with tag definitions and custom icon.
UML- Architecture
Software architecture provides a basic design of a complete software system. It defines the elements
included in the system, the functions each element has, and how each element relates to one another.
The software architect will take several factors into consideration:
Advantages: Architecture provides high productivity to the software team. The software development
becomes more effective as it comes up with an explained structure in place to coordinate work,
implement individual features, or ground discussions on potential issues.
A clear architecture will help to achieve quality in the software with a well-designed structure using
principles like separation of concerns; the system becomes easier to maintain, reuse, and adapt. The
software architecture is useful to people such as software developers, the project manager, the client,
and the end-user. Each one will have different perspectives to view the system and will bring different
agendas to a project. Also, it provides a collection of several views. It can be best understood as a
collection of five views:
2. Design view
3. Implementation view
4. Process view
5. Development view
o It is a view that shows the functionality of the system as perceived by external actors.
o With UML, it is easy to capture the static aspects of this view in the use case diagrams, whereas
its dynamic aspects are captured in interaction diagrams, state chart diagrams, and activity
diagrams.
Design View
o It is a view that shows how the functionality is designed inside the system in terms of static
structure and dynamic behavior.
o With UML, it represents the static aspects of this view in class and object diagrams, whereas its
dynamic aspects are captured in interaction diagrams, state chart diagrams, and activity
diagrams.
Implementation View
o It is the view that represents the organization of the core components and files.
o With UML, its static aspects are expressed in component diagrams, and the dynamic aspects are
captured in interaction diagrams, state chart diagrams, and activity diagrams.
Process View
o It incorporates the threads and processes that make concurrent system and synchronized
mechanisms.
o Its static and dynamic aspects are expressed the same way as the design view but focus more on
the active classes that represent these threads and processes.
Deployment View
o It is the view that shows the deployment of the system in terms of physical architecture.
o It includes the nodes, which form the system hardware topology where the system will be
executed.
o It primarily addresses the distribution, delivery, and installation of the parts that build the
physical system.