Skip to main content

Programming Models

✔ You need to use some programming model to develop any application.

✔ The basic purpose of any programming model is to make programming efficient, i.e., to make the process of writing a complex program:

  • less harder
  • bug-free
  • easily understandable
  • easily modifiable

✔ Following are the two main programming models available to develop applications:

  • Procedure Oriented Programming (POP)
  • Object Oriented Programming (OOP)

3.1.1 Procedure Oriented Programming (POP)

✔ Functions are the main building blocks of POP, i.e., your application will be divided into multiple functions.

✔ In POP, structure can be used to represent the data.


Example

struct stack

{
int top;
char*name;
}

push()
pop()

struct queue

{
int front,rear;
char*name;
}

insert()
delete()

Concept

👉 All functions are global


✔ Here we defined one structure called stack with top and name, and another structure called queue with front, rear, and name.

✔ Two functions are defined:

  • push() and pop() → operate on stack
  • insert() and delete() → operate on queue

✔ In Procedural Oriented Programming Languages:

  • All functions are defined globally
  • There is no way to restrict usage, such as:
    • push(), pop() should be used only with stack
    • insert(), delete() should be used only with queue

💡 Quick Understanding

  • POP = function-based programming
  • Data and functions are separate
  • No restriction → functions can misuse data
  • This limitation led to OOP (next concept)

✔ There is a chance that:

  • push() can use queue
  • insert() can use stack

✔ This may cause problems like:

  • There is no owner for the data → difficult to maintain data integrity
  • Any function can use any data
  • Difficult to identify which function is wrongly using the data
  • etc.

3.1.2 Object Oriented Programming (OOP)

✔ Objects are the main building blocks of OOPS, i.e., your application will be divided into multiple objects.


Example

class Stack

{
int top;
String name[];

push()
pop()
}

class Queue

{
int front,rear;
String name[];

insert()
delete()
}

✔ Explanation

✔ Here we defined a class called Stack with:

  • Data members → top, name
  • Methods → push(), pop() (operate only on Stack data)

✔ We defined another class called Queue with:

  • Data members → front, rear, name
  • Methods → insert(), delete() (operate only on Queue data)

✔ Key Concept

✔ In Object Oriented Programming:

  • Data and methods are encapsulated into a class

✔ This ensures:

  • push() and pop() → work only on Stack
  • insert() and delete() → work only on Queue

⭐ Final Statement

👉 Everything in the world is an object.


💡 Quick Understanding

  • POP → functions are global
  • OOP → data + methods together ✔
  • OOP solves:
    • Data misuse
    • Lack of control
    • Poor maintainability

Object Definition (OOP Concept)

Grady Booch (Father of OOPS) defined an object as follows:

👉 An object has:

  • State
  • Behavior
  • Identity

✔ Explanation

  • State → properties / fields / data
  • Behavior → operations / methods / functions
  • Identity → unique identification of an object

✔ An object:

  • has state
  • exhibits well-defined behavior
  • has a unique identity

✔ Another definition:

An object has state, behavior, and identity;

the structure and behavior of similar objects are defined in their common class;

the terms instance and object are interchangeable.


Key Concept

✔ An object has:

  • State
  • Behavior

✔ State and behavior of an object are defined inside a class.


Example

class Stack {

int top;
String name[];

void push() {}

void pop() {}
}

✔ Mapping

  • int top, String name[] 👉 State / Data members / Fields / Properties
  • push(), pop() 👉 Behavior / Member functions / Methods

💡 Quick Understanding

  • Object = Data + Behavior + Identity
  • Class = blueprint of object
  • Object = instance of class
  • State → variables
  • Behavior → methods