You are on page 1of 2

OBJECT-ORIENTED CONCEPTS

Procedural programming
 Procedural programming is a top-to-bottom approach where in we solve a problem as straightforward as possible by
getting into the main problem, dividing it into smaller subproblems, until we arrive at the solution
 In this approach, we intend to create a program to do a specific task for a specific purpose.
 Traditional programming languages are considered as procedural.
Examples are: C, Pascal, BASIC/VB, Ada and COBOL
 Programming in procedural languages involves choosing data structures, designing algorithms and translating
algorithms into codes
Object-Oriented Programming
 Object-oriented programming is a paradigm based on the concept of “objects”
 This is a concept where we create a data model that defines both the data type and the types of operations that can be
applied to the data model.
 This is an approach to design modular reusable software systems.
What is an object?
 In computer science, an object can be a variable, a data structure, a function, or a method, and as such, is a value in
memory referenced by an identifier
 An object represents a real entity with attributes and behaviors by combining the data and code into one – has a
unique identity in the system
Object-Oriented Programming
 OOP Languages includes Java, C++, Python, Ruby, Objective-C and others.
 Object-oriented programming is always related to real-world objects since we never limit their capabilities to only one
task.
 Just like objects in the real world, what we’re trying to accomplish is a code that could be used in other things that we
didn’t intend to do.
Procedural vs. Object-Oriented Programming
 OO program codes are easier to maintain and update since we only need to inherit the new codes to existing ones. In
procedural programs, we have to recreate the entire code just to make changes or updates.
 OOP languages are more efficient than procedural languages since they can dump or destroy unused codes for better
runtime. Procedural languages reads through the entire code before running.
 OOP has Access Modifiers named Public, Private and Protected for data encapsulation
 Procedural programming focuses on functions while Object-oriented programming focuses on objects
 Procedural programs have a short scope of features since we program them on what we intend to do. OOP programs
tends to be more abstract.
 OOP Languages has more features like inheritance and polymorphism.
o Inheritance – adoption of all non-private properties and methods of one class to the other
o Polymorphism – ability of one object to take on many forms and functions.
Abstract Data Types (ADTs)
• An abstract data type(ADT) is a logical description of how data is viewed as well as the operations that are allowed without
regard to how they will be implemented.
Benefits of using ADT:
• Code easier to understand
• Implementations of ADTs can be changed without requiring changes to the program that uses ADTs.
• ADTs can be use in future programs.
Two parts of ADT:
Public or external - the data and the operations
Private or internal- the representations and the implementation
Abstract data types:
• Linked List is for storing elements where each is a separate objects.
• Stack is an ordered list in which insertion and deletion are done at one(1) end.
• Queue is an ordered list in which insertion and deletion are done at separate ends.
• Tree represents a hierarchical nature of a structure in a graphical form.
• Priority Queue is used for retrieving and removing either the minimum or maximum element.
• Heap is a partially sorted binary tree.
• Set represents a collection of elements that do not have to be in order.
• Map is a set of ordered pairs with elements know as key and value.
• Graph consists of a set of points/nodes (vertices) and set of links (edges) which connects the pair of vertices.
Object-Oriented Programming Concepts
Inheritance
- Enables the use of an existing class to define new classes
- Uses the keyword extend
A. Types of Inheritance Classes
- Derived Classes (also know as subclasses, child classes and descendant classes) are defined by adding instance variables
and methods to an existing class.
- Bases Classes (also known as superclasses, parent classes, and ancestor classes) are the existing class where the derived
class is built upon.
Inheritance Classes:

1. Derived Class
Example:

public class Student extends Person {

1. Base Class
Example:

public class Student extends Person {

}
B. Constructors in Derived Class
- this classes do not inherit constructors from its base class = this Method
- use the super keyword within a derived class as the name of a constructor
in the base class. Example:
C. this method public Person()
- calls the constructor of the same class when used in a constructor
{
this(“No name yet”);
Polymorphism }
Ability of an object to take on many forms.

Polymorphism
Dynamic Binding
Example:
public class A {
void method1(){
System.out.println(“method1 of class A”);
}
public class Binding {
public static void main(String[] args){
A a1 = new A();
a1.method1();
}
}
Call from a1.method1() binds to corresponding method1() definition.
Interface Abstract Classes
Used to specify methods that a class must implement Classes that cannot be instantiated but can subclassed(defining of
of a new class from older class or superclass, with some changes.

Syntax:
public interface Interface_Name; Abstract Classes
Example: Syntax:
public interface Measurable { public abstract ClassName {
public double getPerimeter();
public double getArea(); }
} Abstract Methods
/** Interface method Measurable returns Syntax:
the perimeter and area of an object. **/ public abstract void MethodName();

You might also like