Concept of OOP
Concept of OOP
ITRACKC1
CHAPTER 1
Basic Concept of
Object-Oriented Programming
LESSON 1
Concept of Object-Oriented Programming
FEBRUARY 8, 2025
BASIC CONCEPT OF OOPs
Object-Oriented Programming (OOP) refers to a type of computer
programming (software design) in which programmers define
the data type of a data structure, and also the types of operations
(functions) that can be applied to the data structure.
Logic programming paradigms – It would solve logical problems like puzzles, series etc.
In logical programming the main emphasize is on knowledge base and the problem. The
execution of the program is very much like proof of mathematical statement.
Functional programming paradigms – The functional programming paradigms has its
roots in mathematics and it is language independent. The key principle of this paradigms
is the execution of series of mathematical functions. The central model for the abstraction
is the function which are meant for some specific computation and not the data structure.
Data are loosely coupled to functions.The function hide their implementation. Function
can be replaced with their values without changing the meaning of the program.
CONCEPT OF OOPs
It is necessary to understand some of the concepts used
extensively in object-oriented programming. These include:
Object
• Objects have states and behaviors.
• An object is an instance of a class.
• An object is created from a class using the new keyword.
Objects store data and perform operations, making them
essential for organizing and structuring programs efficiently.
CONCEPT OF OOPs
Object
CONCEPT OF OOPs
Object
Programming problem is analyzed in term of objects and the nature of
communication between them. Program objects should be chosen such that they
match closely with the real-world objects. (Entity)
Representing an Object:
CONCEPT OF OOPs
Class
A class can be defined as a template/blueprint for creating objects in object-
oriented programming (OOP) It defines the attributes (properties or data) and
methods (functions or behaviors) that the objects created from the class will
have. A class encapsulates data and the operations that can be performed on it,
promoting modular and reusable code.
The Student class has three attributes: name, age, and course.
CONCEPT OF OOPs
Class
The entire set of data and code of an object can be made a user-defined data
type with the help of class. In fact, objects are variables of the type class. Once a
class has been defined, we can create any number of objects belonging to that
class.
Inheritance is one of the key features of OOP that allows us to create a new class from an
existing class.
Inheritance
In object-oriented programming, inheritance enables new objects to take on the
properties of existing objects. A class that is used as the basis for inheritance is called
a superclass or base class.
A class that inherits from a superclass is called a subclass or derived class. The
terms parent class and child class are also acceptable terms to use respectively. A child
inherits visible properties and methods from its parent while adding additional properties
and methods of its own.
Inheritance
TWO OBJECTS OF INHERITANCE
Subclassing – making a new class based on a previous one.
Overriding – changing how a previous class works
You can organize your objects into a hierarchy. Using inheritance to make this
hierarchy often creates easier to understand code, but most importantly it allows you to
reuse and organize code more effectively.
Polymorphism
Polymorphism (from Greek, meaning “many forms”) is a feature that allows one interface
to be used for a general class of actions. The specific action is determined by the exact
nature of the situation. Consider a stack (which is a last-in, first-out list). You might have a
program that requires three types of stacks. One stack is used for integer values, one for
floating-point values, and one for characters. The algorithm that implements each stack
is the same, even though the data being stored differs. In a non–object-oriented
language, you would be required to create three different sets of stack routines, with each
set using different names. However, because of polymorphism, in Java you can specify a
general set of stack routines that all share the same names.
Polymorphism means "many forms", and it occurs when we have many classes that are
related to each other by inheritance. Polymorphism uses those methods to perform
different tasks or ability to process objects differently depending on their data type or
class. This allows us to perform a single action in different ways.
Other concept of OOPs
Methods − A method is basically a behavior. A class can contain many methods. It is in
methods where the logics are written, data is manipulated and all the actions are
executed.
Instance Variables − Each object has its unique set of instance variables. An object's state
is created by the values assigned to these instance variables.
Interface – The languages and codes that the applications use to communicate with
each other and with the hardware.
ITRACKC1
CHAPTER 1
Basic Concept of
Object-Oriented Programming
LESSON 2
Benefits of Object-Oriented Programming
FEBRUARY 8, 2025
Benefits of OOPs
OOP has become a fundamental part of software development. Thanks to the
ubiquity of languages like Java and C++, you can’t develop software for mobile
unless you understand the object-oriented approach. The same goes for serious
web development, given the popularity of OOP languages like Python, PHP and
Ruby. Getting your head around the idea of object-oriented programming can be
challenging for some IT professionals.
Benefits of Object-Oriented
Programming
MODULARITY FOR EASY TROUBLESHOOTING
That’s the beauty of encapsulation. Objects are self-contained, and each bit of
functionality does its own thing while leaving the other bits alone. Also, this
modality allows an IT team to work on multiple objects simultaneously while
minimizing the chance that one person might duplicate someone else’s
functionality.
Benefits of Object-Oriented
Programming
REUSE OF CODE THROUGH INHERITANCE
A generic class, such as Car, is created to encapsulate shared attributes and
methods. Subclasses like RaceCar and Limousine inherit these shared traits,
reducing redundant code. Subclasses can also define their unique attributes and
methods, like "fireAfterBurners" for RaceCar or a "Chauffeur" for Limousine.
Inheritance not only saves time but also allows for centralized updates—changes
made to the parent Car class automatically apply to all subclasses.
Benefits of Object-Oriented
Programming
FLEXIBILTY THROUGH POLYMORPHISM
This is where object-oriented programming’s sweet polymorphism comes into
play. Because a single function can shape-shift to adapt to whichever class it’s in,
you could create one function in the parent Car class called “drive” — not
“driveCar” or “driveRaceCar,” but just “drive.” This one function would work with the
RaceCarDriver, LimousineDriver, etc. In fact, you could even have
“raceCar.drive(myRaceCarDriver)” or “limo.drive(myChauffeur).”
Benefits of Object-Oriented
Programming
DATA REDUNDANCY
This is a condition created at the place of data storage (you can say Databases)
where the same piece of data is held in two separate places. So, the data
redundancy is one of the greatest advantages of OOP. If a user wants a similar
functionality in multiple classes, he/she can go ahead by writing common class
definitions for the similar functionalities and inherit them.
Benefits of Object-Oriented
Programming
EFFECTIVE PROBLEM SOLVING
Writing software in a top-down language is like playing Jenga while wearing
mittens. The more complex it gets, the greater the chance it will collapse.
Meanwhile, writing a functional-style program in a language like Haskell or ML can
be a chore.
Object-oriented programming is often the most natural and pragmatic approach,
once you get the hang of it. OOP languages allows you to break down your
software into bite-sized problems that you then can solve — one object at a time.
Benefits of Object-Oriented
Programming
CODE MAINTENANCE
This feature is more of a necessity for any programming languages, it helps users
from doing re-work in many ways. It is always easy and time-saving to maintain
and modify the existing codes with incorporating new changes into it.
Benefits of Object-Oriented
Programming
SECURITY
With the use of data hiding and abstraction mechanism, we are filtering out
limited data to exposure which means we are maintaining security and providing
necessary data to view.
CATANDUANES STATE UNIVERSITY
COLLEGE OF INFORMATION AND COMMUNICATIONS TECHNOLOGY
ITRACKC1
CHAPTER 1
Basic Concept of
Object-Oriented Programming
LESSON 3
Object vs. Class
FEBRUARY 8, 2025
Objects vs. Classes
The class is at the core of Java. It is the logical construct upon which the entire
Java language is built because it defines the shape and nature of an object. As
such, the class forms the basis for object-oriented programming in Java. Any
concept you wish to implement in a Java program must be encapsulated within a
class.
Objects vs. Classes
May represent:
Real world objects – Car, Person, Phone, Book, etc.
Concepts – Time, Bank Account, Sale, etc.
An object has:
State – variables/data/attributes
Behavior – operators/codes/methods
Each object has its own data, through the code within a class is shared for
economy
Example Car Object
ATTRIBUTES:
Current Gear = 1st
Speed = 5kph
METHODS:
Brake
Shift gear
Accelerate
Back up
Steer
Example Bank Account
ATTRIBUTES:
Name
Number
Balance
METHODS:
Deposit
Withdraw
Close
Get Balance
Get Name
Get Number
What is a classes?
A class is a blueprint or prototype that defines the attributes and methods common to
all objects of a certain kind.
Programmers can use a class repeatedly to create numerous objects of a certain kind.
Most basic structure of object-oriented programming.
A class is declared by use of the class keyword. The classes that have been used up to
this point are actually very limited examples of its complete form. Classes can (and
usually do) get much more complex.
The general form of a class
The data, or variables, defined within a class are called instance variables. The code is
contained within methods. Collectively, the methods and variables defined within a
class are called members of the class. In most classes, the instance variables are
acted upon and accessed by the methods defined for that class. Thus, as a general
rule, it is the methods that determine how a class’ data can be used.
Variables defined within a class are called instance variables because each instance
of the class (that is, each object of the class) contains its own copy of these variables.
Thus, the data for one object is separate and unique from the data for another. We will
come back to this point shortly, but it is an important concept to learn early.
The general form of a class
All methods have the same general form as main(), which we have been using thus
far. However, most methods will not be specified as static or public. Notice that the
general form of a class does not specify a main() method. Java classes do not need to
have a main() method. You only specify one if that class is the starting point for your
program. Further, some kinds of Java applications don’t require a main() method at all.
Declaring Classes
Syntax:
[modifier] class className {
attribute declaration
constructor declaration
method declaration
}
Modifier
Optional
Can be keywords, abstract/final, and public
Coding Conventions
Class names should be:
Nouns, in mixed case with the first letter of each internal word capitalized.
For example:
BankTransaction, UserAccount
Where:
Modifier – optional, can be public, private, protected, final, static
Type – can be a class name or a primitive data type
Name – any valid identifier
Default value – optional initial value
Example of declaring attributes
private boolean isReady;
final String message = “Hello”;
int x = 10;
ITRACKC1
THANK YOU