OOP
• Object-oriented programming (OOP) is a programming language model organized
around objects rather than "actions" and data rather than logic.
• The first step in OOP is to identify all the objects the programmer wants to manipulate
and how they relate to each other, an exercise often known as data modeling.
• Once an object has been identified, it is generalized as a class of objects which defines
the kind of data it contains and any logic sequences that can manipulate it.
• Each distinct logic sequence is known as a method.
• Objects communicate with well-defined interfaces called messages.
Write the advantages of OOPS.
•
• Advantages of OOP are;
•
• i.The complexity of the software can be merged easily.
• ii. The data hiding concept helps the programmer to build secure programs.
• iii. Through class concept, we can define the user defined data types.
• iv. The inheritance concept can be used to eliminate the redundant code.
• v. The message passing concept helps the programmer for communicating between
different objects.
• vi. Through the inheritance concept, we can define different classes with combined
features.
• viii. OOP treats data as critical around the program. element and do not allow to flow
freely
• ix OOP ties data elements more closely to functions that it operates on.
Procedural Oriented Programming
1
• It is divided into small parts called functions.
• The function is more important than the data
• Adding new data and functions is not easy.
• It follows a top-down approach.
• It does not have any proper way of hiding data and inheritance, so it is less secure.
• There is not code reusability.
• It has no access specified in procedural programming.
• It is used for designing medium- sized programs.
• Examples: C, FORTRAN, Pascal, BASIC
•
• OOP
•
• OOP is a programming paradigm using objects, and methods to design applications and
computer programs.
• It uses bottom-up development process.
• Class and object are the main idea of object oriented programming.
•
• It includes features such as data abstraction, encapsulation, modularity, polymorphism,
and inheritance. In OOP emphasis is given to data more closely to the functions that
operate on.
• Object-Oriented Programming
• It is divided into small parts called objects.
• Data is more important than function.
• Adding new data and function is easy.
• It follows a bottom-up approach. It provides data hiding and inheritance, so it is more
secure.
• There is code reusability.
• Object-oriented programming has access specifies like private, public, protected.
• It is used for designing large and complex programs. Examples: C++, Java, Python, C#
• Distinguish between OOP and procedural language.
Benefits of OOP
The concept of a data class makes it possible to define subclasses of data objects that share
some or all of the main class characteristics. Called inheritance, this property of OOP forces
a more thorough data analysis, reduces development time, and ensures more accurate coding.
• Since a class defines only the data it needs to be concerned with, when an instance of that
class (an object) is run, the code will not be able to accidentally access other program
data. This characteristic of data hiding provides greater system security and avoids
unintended data corruption.
2
• The definition of a class is reusable not only by the program for which it is initially
created but also by other object-oriented programs (and, for this reason, can be more
easily distributed for use in networks).
• The concept of data classes allows a programmer to create any new data type that is not
already defined in the language itself.
Procedural Language
•
• Procedural language is a collection of instructions which are executed by the computer
sequentially. It uses top-down development process.
• Function (library or user defined) are the main idea of structured programming.
•
• Emphasis is given to procedure.
What is the Difference Between Structured and Object Oriented Programming
The main difference between structured and object oriented programming is that structured
programming allows developing a program using a set of modules or functions, while object
oriented programming allows constructing a program using a set of objects and their interactions.
A computer program is a set of instructions that instruct the CPU to perform a defined task. We
can write computer programs using various programming languages. Furthermore, a
programming paradigm is a way of categorizing a programming language depending on its
features. Two such paradigms are structured and object oriented programming.
Key Areas Covered
1. What is Structured Programming
– Definition, Functionality
2. What is Object Oriented Programming
– Definition, Functionality
3. Difference Between Structured and Object Oriented Programming
– Comparison of Key Differences
Key Terms
C Language, Modular Programming, Object Oriented Programming, Structured Programming
3
4
What is Structured Programming
Structured Programming divides a program into a set of functions or modules. Modular
programming is another name for this. These functions have statements embraced inside curly
braces. Each of these functions performs a subtask. Usually, as each function represents a
specific functionality, it is easier for the programmer to test and debug the code, but this can
differ depending on the program. C language and Pascal are two common structured
programming languages.
In the structured programming C, the user can create his own user-defined functions. The main
function calls the other functions. It indicates the execution of the program. When there is
a function call, the control is passed to that function. After completing the function, the control
passes back to the main program. Moreover, a variable inside a function is a local variable,
and global variables are accessible by all the functions.
What is Object Oriented Programming?
Object oriented programming allows the programmer to represent real-world scenarios
using objects. An object is any entity that has states and behaviours. States represent the
attributes or data of an object, whereas the methods represent the behaviours of objects. Student,
Employee, Book etc. are objects. These objects interact with other objects by passing messages.
Furthermore, a class is a blueprint for creating an object. It is necessary to have a class to create
objects. For example, to create an Employee object, there should be an Employee class.
5
In addition to classes and objects, there are four major pillars in OOP. They are as follows.
Encapsulation – Binds or combines properties and methods into a single unit
Inheritance – Allows a class to use properties and methods of an already existing class
Polymorphism – Allows an object to perform in multiple ways – Overloading and overriding
are two ways of achieving polymorphism.
Abstraction – Hides the internal details and displays only the functionalities to the user –
Moreover, abstract classes and interfaces help to achieve abstraction.
Overall, object oriented programming makes it easier to develop the program. Furthermore, it
provides data security, maintainability and code reusability.
Difference Between Structured and Object Oriented Programming
Definition
Structured programming is a programming paradigm which divides the code into modules or
function, while OOP is a programming paradigm based on the concept of objects, which contain
data in the form of fields known as attributes, and code in the form of procedures known as
methods. Thus, this explains the main difference between structured and object oriented
programming.
6
Main Focus
Furthermore, structured programming focuses on dividing the program into a set of functions in
which each function works as a subprogram while object oriented programming focuses on
representing a program using a set of objects which encapsulates data and object.
Modification
Moreover, it is difficult to modify the structured programs while it is easier to modify the Object
Oriented programs.
Communication
In structured programming, the main method communicates with the functions by calling those
functions in the main program whereas, in object oriented programming, the objects
communicate with each other by passing messages. Hence, this is an important difference
between structured and object oriented programming.
Access Specifiers
There are no access specifiers in structured programming while there are access specifiers such
as private, public and protected in Object Oriented Programming. Thus, this is also an important
difference between structured and object oriented programming.
Security
Besides, data is not secure in structured programming, but it is secure in object oriented
programming.
Code Reusability
Also, it is difficult to reuse code in structured programming, whereas it is easier to reuse code in
object oriented programming.
Conclusion
Overall, structured and object oriented programming are two major programming paradigms.
The main difference between structured and object oriented programming is that structured
programming helps to develop a program using a set of modules or functions while object
oriented programming helps to construct a program using a set of objects and their interactions.
7
Features of OOP
Simple:
• OOP easy to learn.
• It is easy to write programs using Java.
• Most of the complex or confusing features in C++ are removed in Java like pointers etc.
Secure:
• OOP provides data security through encapsulation.
• Also we can write applets in Java which provides security.
• An Applet is a small program which can be downloaded from one computer to another
automatically.
• There is no need to worry about applets accessing the system resources which may compromise
security.
• Applets are run within the JVM which protects from unauthorized or illegal access to system
resources
Portable:
• Applications written using OOP are portable in the sense that they can be executed on
any kind of computer containing any CPU or any operating system.
• When an application written in Java is compiled, it generates an intermediate code file
called as “bytecode”.
8
• Bytecode helps Java to achieve portability.
• This bytecode can be taken to any computer and executed directly.
CODE STRUCTURE IN JAVA(OOP)
Put a class In a source file.
Put methods In a class.
Put statement In a method.
What goes In a class?
• A class has one or more method.
• In the Dog class, the bark method will hold Instructions for how the Dog should bark.
9
• Your methods must be declared inside a class
(In other words, within the curly braces of the class).
• public class Dog {
void bark() {
}
}
What goes In a method?
• Within the curly braces of a method, write your instructions for how that method should
be performed.
Method code is basically a set of statements, and for now you can think of a method kind of like
a function or procedure.
Public class Dog{
void bark(){
Statement 1;
Statement 2;
Statements
Anatomy of a class
• When the JVM starts running, it looks for the class you give it at the command line.
• Then it starts looking for a specially-written method that looks exactly like:
public static void main (String[ ] arqs) {
//your code goes here
10
• Next, the JVM runs everything between the curly braces { } of your main method.
• Every Java application has to have at least one class, and at least one main method
(not one main per class just one main per application).
First Java Program
public class HelloWorld{
public static void main(String []args){
System.out.println(“Hello World”);
Save as: HelloWorld.java
Compile: javac HelloWorld.java
Run: java HelloWorld
Application of OOP
Now we have a basic idea of what object-oriented programming means, now let’s look at some
of the applications of OOPs.
Real Time Systems
The term “real-time system” refers to any information processing system with hardware and
software components that perform real-time application functions and can respond to events
within predictable and specific time constraints. For real-time computing, timeliness and time
synchronization are the two requirements. Timeliness means the ability to produce the expected
result by a specific deadline and time synchronization means the capability of agents to
coordinate independent clocks and operate together in unison. Using Object-oriented technology,
we can develop real-time systems, this will offer adaptability, ease of modifications, reusability
for the code. There is a lot of complexity involved in designing real-time systems, OOP
techniques make it easier to handle those complexities.
11
Client Server System(search yourself)
The client-server systems are those that involve a relationship between cooperating programs in
an application. In general, the clients will initiate requests for services and the servers will
provide that functionality. The client and server either reside in the same system or communicate
with each other through a computer network or the internet.
The concepts of OOPs are quite useful when designing client-server systems. Object-oriented
client-server systems are used to provide the IT Infrastructure that creates Object-oriented server
internet or the OCSI applications. The infrastructure refers to the operating systems, networks,
and hardware. OCSI contains the following main technologies
The Client Server
Object Oriented Programming
The Internet
Hypertext and Hypermedia
Hypertext is non-linear, multi-sequential, a cross-referencing tool that connects the links to other
texts, Example of Hypertext is that InterviewBit, when we read one article it uses hypertext to
12
link other pages and when we click on that hypertext it takes to us to that page so that we can
gather more information related to the topic. Hypermedia is the extension to hypertext including
multiple forms of media like graphics, text, audio, and video, etc. An example of hypermedia is
that when we use an e-commerce site say Amazon and when we click on any product it takes us
to the specific product page which belongs to that. So here the link is embedded in the
image.OOP also helps in laying the framework for hypertext and hypermedia
Object Oriented Database
Nowadays each and every data is being stored and processed, the traditional model of storing
data i.e the relational model stores each and every piece of data in tables that consist of rows and
columns. However as complexity grows, storing in the form of tables becomes quite
cumbersome, here the need for storing in the form of real-world objects comes into the picture.
These databases try to maintain a direct correspondence between the real-world and database
objects in order to let the object retain its identity and integrity. They can then be identified and
operated upon.
A popular example of object-oriented databases is MongoDB.
13
Neural Networks and Parallel Programming
A neural network is a series of algorithms that endeavors to recognize underlying relationships in
a set of data through a process that mimics the way the human brain operates. In this sense,
neural networks refer to systems of neurons, either organic or artificial in nature.
Parallel programming involves the division of a problem into smaller subproblems, the
subproblems can be executed at the same time using multiple computing resources. OOPs, are
used to simplify the process by simplifying the approximation and prediction ability of the
network.
14
AI Expert Systems
An AI Expert system is the one that simulates the decision-making ability of a human expert, the
expert knowledge can be increased using different add-ons to the knowledge base or in simple
words the addition of rules. For example, PXDES is an expert system that predicts the degree
and type of lung cancer. There are many expert systems out there.
OOPs, power the development of such AI Expert systems, To AI systems use forward and
backward chaining to reach a conclusion. Basically, the chaining involves a chain of conditions
and derivations to deduce the outcome. An AI system has to be reliable, highly responsive, and
offers a high performance, to power such capabilities OOPs are used.
Simulation and Modeling System
Modeling a complex system is quite difficult owing to the varying specifications of the variables,
such types of systems are prevalent in medicine and in other areas of natural science, like
zoology, ecology, and agronomic systems. Simulation and modeling systems are the imitations
of the real world product. The system’s workings can be checked and analyzed using object-
oriented programming.
15
A good example of a simulation and modeling system is of automobiles such as cars, Once the
model of the car structure is developed by the engineer’s team, as and when they feel that the
product is good to go they can release the product. OOP provides an appropriate approach for
simplifying these complex models.
Office Automation Systems
Nowadays companies use automated systems to share information and communication to and
from the people inside and outside the organization. There are various works in the office for
which the employees can be replaced by automated robots and these works are generally time-
consuming and hard work. The company can reduce its cost expenses by developing such a
system.
To develop office automation systems, robot programming automation or RPA is used. RPA
uses Object-oriented programming.
CIM/CAD/CAM Systems
OOP can also be used in manufacturing and designing applications as it allows people to reduce
the efforts involved. For instance, it can be used while designing blueprints and flowcharts. So it
makes it possible to produce these flowcharts and blueprint accurately.
16
Computer Aided Designs
As per Wikipedia, Computer-aided design (CAD) is the use of computers (or workstations) to
aid in the creation, modification, analysis, or optimization of a design. In mechanical design, it is
known as mechanical design automation (MDA), which includes the process of creating a
technical drawing with the use of computer software.
One of the good examples of computer-aided design is Matlab. It is used by the programmers to
solve difficult mathematical models, these models are then used in bigger system designs to
check whether the system will function as expected or not
EXTRA:
What is OOP
Object-Oriented Programming (OOP) is a programming paradigm that relies on the concept of
classes and objects. It is used to structure a software program into simple, reusable pieces of code
blueprints (usually called classes), which are used to create individual instances of objects. There
are many concepts of OOPs such as inheritance, data binding, polymorphism, etc. The
programming paradigm where everything is represented as an object is known as a truly object-
oriented programming language. Smalltalk is considered the first truly object-oriented
programming language.
17
Objects: Any entity that has state and behavior is known as an object, for example,
tables, pen etc. It can be defined as an instance of class, it contains an address and takes
up some space in memory. They can communicate with each other without knowing the
details of each other’s data or code.
Class: Collection of multiple objects is called class, It is a blueprint from which you can
create an individual object. They represent broad categories that share attributes.
Inheritance: When one class acquires all the properties and behaviors of a parent object,
it is known as inheritance. It provides code reusability.
Polymorphism: Polymorphism means having many forms, It is the ability of an object to
take on many forms.
Abstraction: It is the property by virtue of which only the essential details are displayed
to the user, the non-essential details are hidden from the end users.
Encapsulation: It is defined as the wrapping up of data under a single unit. It is the
mechanism that binds together code and the data it manipulates.
There are many advantages(features) of OOPs like reusability, data redundancy, code
maintenance, security, better productivity, and design benefits.
18