INTRODUCTION TO OOP
Objective:
•Know the difference between functional programming
and OOP
• Know the importance of OOP
• Know four design principles of OOP
• Know OOP programming languages
1
STRUCTURED vs. OO PROGRAMMING
STRUCTURED PROGRAMMING:
Procedural programming is about writing methods
that perform operations on the data.
•Disadvantage of structure programming :-
-Code Reusability and Modularity
-Maintainability and Scalability
Object-oriented programming is about creating
objects that contain both data and methods.
2
Why OOP?
Save development time (and cost) by reusing
code
once an object class is created it can be used in
other applications
Easier debugging
classes can be tested independently
reused objects have already been tested
33
OOPs PROGRAMMING
Object-Oriented Programming is a methodology
to design a program using classes and objects. It
simplifies software development and maintenance
by providing some concepts Object, Class,
Inheritance, Polymorphism, Abstraction,
Encapsulation.
4
OBJECT ORIENTED PROGRAMMING
Four main design principles of Object-Oriented
Programming(OOP):
Encapsulation
Abstraction
Polymorphism
Inheritance
5
Encapsulation
• Definition: Binding data and member functions
together inside a single unit.
• Example: Java class with private data
members and public methods.
• a capsule, it is wrapped with different
medicines.
6
Abstraction
• Hiding internal details and showing functionality is
known as abstraction. Example phone call.
•Abstraction defines way to abstract or hide your
data and members from outside world.
7
Polymorphism
If one task is performed in different
ways, it is known as polymorphism.
For example: speak something; for
example, a cat speaks meow, dog barks
woof, etc.
8
Inheritance
• When subclass acquires all the properties and
behaviours of a superclass, it is known as
inheritance. It provides code reusability. -Subclass
(child) - the class that inherits from another class
Superclass (parent) - the class being inherited from
9
An Inheritance Hierarchy
Superclass
Vehicle
Subclasses
Automobile Motorcycle Bus
Sedan Sports Car Luxury Bus School Bus
What properties does each vehicle inherit from the types
of vehicles above it in the diagram?
10
10
Class and Object
A class is collection of variables and
methods, and this is a blue print of an
object.
class is a template definition of the
methods and variable.
Class doesn't consume any memory.
11
Class and Object
The object is an instance of class. That has all
property of class.
The object is a clone of class and it has a
copy of all variables and methods.
public class Emp {
int x = 5;
public static void main(String[] args) {
Emp myObj = new Main();
System.out.println(myObj.x);
}
}
12
OOPs in Real World
• OOP in Real-world Applications
• Examples of popular programming languages that
use OOP
•e.g. Java, C++, Python, C#
• Real-world applications and industries that benefit
from OOP principles example Banking and Finance,
Healthcare System, E-commerce platform.
13
Advantage of OOPs
• Importance of OOP in software development
- OOP is faster and easier to execute
-OOP provides a clear structure for the
programs
-OOP helps to keep the Java code DRY
"Don't Repeat Yourself", and makes the code
easier to maintain, modify and debug
-OOP makes it possible to create full reusable
applications with shorter development time
14
Object-Oriented Programming Languages
Pure OO Languages
Smalltalk, Eiffel, Actor, Java
Hybrid OO Languages
C++, Objective-C, Object-Pascal
15