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

Concept of OOP

The document discusses the fundamental concepts of Object-Oriented Programming (OOP), including key principles such as classes, objects, inheritance, encapsulation, abstraction, and polymorphism. It highlights the benefits of OOP, such as modularity, code reuse, flexibility, effective problem-solving, and enhanced security. Additionally, it explains the distinction between objects and classes, emphasizing that classes serve as blueprints for creating objects, encapsulating both data and behavior.

Uploaded by

artkaine lopero
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)
8 views

Concept of OOP

The document discusses the fundamental concepts of Object-Oriented Programming (OOP), including key principles such as classes, objects, inheritance, encapsulation, abstraction, and polymorphism. It highlights the benefits of OOP, such as modularity, code reuse, flexibility, effective problem-solving, and enhanced security. Additionally, it explains the distinction between objects and classes, emphasizing that classes serve as blueprints for creating objects, encapsulating both data and behavior.

Uploaded by

artkaine lopero
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/ 50

CATANDUANES STATE UNIVERSITY

COLLEGE OF INFORMATION AND COMMUNICATIONS TECHNOLOGY

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.

Object-Oriented Programming is a programming style which is


associated with the concepts like class, object, inheritance,
encapsulation, abstraction, and polymorphism.

In this way, the data structure becomes an object that includes


both data and functions. In addition, programmers can create
relationships between one object and another. For example,
objects can inherit characteristics from other objects.
The Programming Paradigms
What is paradigm?
Paradigm can also be termed as method to solve some problem
or do some task. Programming paradigm is an approach to
solve problem using some programming language or also we
can say it is a method to solve a problem using tools and
techniques that are available to us following some approach.
1. Imperative Programming
Paradigm
A program can be conceptually organized around its code or around its data. That is,
some programs are written around “what is happening” and others are written around
“who is being affected.”

Process-Oriented Paradigm – This approach characterizes a program as a series of


linear steps (that is, code). The process-oriented model can be thought of as code acting
on data. Procedural languages such as C employ this model to considerable success.
However, problems with this approach appear as programs grow larger and more
complex.
Object-Oriented Programming – Object-oriented programming organizes a program
around its data (that is, objects) and a set of well-defined interfaces to that data. An
object-oriented program can be characterized as data controlling access to code. As you
will see, by switching the controlling entity to data, you can achieve several organizational
benefits.
2. Declarative Programming
Paradigm
The declarative programming is a style of building programs that expresses logic of
computation without talking about its control flow. It often considers programs as theories
of some logic. It may simplify writing parallel programs. The focus is on what needs to be
done rather how it should be done basically emphasize on what code is actually doing. It
just declares the result we want rather how it has be produced. This is the only difference
between imperative (how to do) and declarative (what to do) programming paradigms.

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.

A class is thus a collection of objects similar types.


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. Methods are reusable and can be called multiple times from different
parts of a program, helping to organize code, reduce redundancy, and improve
readability.
CONCEPT OF OOPs
Abstraction
The process of picking out (abstracting) common features of objects and procedures.
An essential element of object-oriented programming is abstraction. Humans manage
complexity through abstraction. For example, people do not think of a car as a set of tens
of thousands of individual parts. They think of it as a well-defined object with its own
unique behavior. This abstraction allows people to use a car to drive to the grocery store
without being overwhelmed by the complexity of the individual parts. They can ignore the
details of how the engine, transmission, and braking systems work. Instead, they are free
to utilize the object as a whole. In simple term, Data abstraction is the process of hiding
certain details and showing only essential information to the user.
Encapsulation
Encapsulation is the mechanism that binds together code and the data it manipulates,
and keeps both safe from outside interference and misuse. One way to think about
encapsulation is as a protective wrapper that prevents the code and data from being
arbitrarily accessed by other code defined outside the wrapper. Access to the code and
data inside the wrapper is tightly controlled through a well-defined interface. In simple
term, a procedure is a type of encapsulation because it combines a series of computer
instructions.
Inheritance
Inheritance is the process by which one object acquires the properties of another object.
This is important because it supports the concept of hierarchical classification.
An inheritance is a feature that represent the “is a” relationship between different classes.
For example, a Golden Retriever is part of the classification dog, which in turn is part of the
mammal class, which is under the larger class animal. Without the use of hierarchies,
each object would need to define all of its characteristics explicitly. However, by use of
inheritance, an object need only define those qualities that make it unique within its class.
It can inherit its general attributes from its parent. Thus, it is the inheritance mechanism
that makes it possible for one object to be a specific instance of a more general case.

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.

Information Hiding - The process of hiding details of an object or function. Information


hiding is a powerful programming technique because it reduces complexity.

Interface – The languages and codes that the applications use to communicate with
each other and with the hardware.

Messaging – Message passing is a form of communication used in parallel programming


and object-oriented programming.

Procedure – A section of a program that performs a specific task.


CATANDUANES STATE UNIVERSITY
COLLEGE OF INFORMATION AND COMMUNICATIONS TECHNOLOGY

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

Image from: https://www.geeksforgeeks.org/understanding-classes-and-objects-in-java/


What is an object?
An object combines data and code that acts on that data.

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--the basic building block of an object-oriented language such as Java--is a


template that describes the data and behavior associated with instances of that class.
The general form of a class
When you define a class, you declare its exact form and nature. You do this by
specifying the data that it contains and the code that operates on that data. While very
simple classes may contain only code or only data, most real-world classes contain
both. As you will see, a class’ code defines the interface to its data.

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

The filename should have the same name as your class.


Strictly speaking, the filename should have the same name as the public class in
your file.
Example code of declaring class
Declaring attributes
Syntax:
[modifier] type name [=default_value];

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;

//You can declare multiple attributes in a single line:


Date birthday, christmasDay;

public class BankAccount {


float balance;
String name;
long number;
}
Coding conventions
• Declare all your attributes on the top of the class declaration.
• Variables’ first letter should be lower case.
• Internal words should start with a capital letter.
• Use an appropriate data type for each attribute you declare.

For Static Attributes


• Class variables
• Allocated once regardless of how many objects are created.
• Can be accessed even without creating an object
ClassName.staticAttribute
amt = BankAccount.minBalance;

• To declare an attribute to be static, use the static modifier.


static float minBalance = 20000.00f;
Sample static attributes
Return statement
The return statement in Java is used to exit a method and optionally return a value to
the caller. It is commonly used in methods that perform calculations, retrieve values, or
make decisions.

Used to exit from the current method.


Flow of control returns to the statement that follows the original method call.
CATANDUANES STATE UNIVERSITY
COLLEGE OF INFORMATION AND COMMUNICATIONS TECHNOLOGY

ITRACKC1

THANK YOU

You might also like