Introduction to OOP
- SUBANGKAR KARMAKER SHANTO
WHAT IS PROGRAMMING?
❑Instruction to computer/device to perform task
❑Computer understands only 0 and 1. Nothing else
❑We need to send the instruction in the form of 0, 1
❑ Feasible?
CLASSIFICATION/EVOLUTION OF
PROGRAMMING
▪Machine level programming
▪ Pure binary instruction
▪Assembly level programming
▪ Write codes:
MOV AX, BX
ADD AX, CX
▪ Assembler converts them to binary
▪High level programming
▪ Close to English Language:
area = height * width
▪ Compiler converts to binary
CLASSIFICATION OF
HIGH LEVEL PROGRAMMING
▪Non structured
▪Sequential and has GOTO
▪Structured or Procedural
▪Use Function/Subroutine
▪Object Oriented programming (OOP)
▪Organized around objects rather than "actions" and data rather than
logic
OBJECT ORIENTED PROGRAMMING
(OOP)
Object oriented programming
Object-oriented programming (OOP) is a way to organize and
conceptualize a program as a set of interacting objects
▪Programmer defines the types of objects that will exist
▪Programmer creates object instances as they are needed
▪Programmer specifies how these various object will communicate
and interact with each other
What is an Object?
▪Real-world objects: Dog, Car, Bank Account, Animal
▪Have Attributes and Behaviors
▪Examples:
▪ Dog:
▪ Attributes: breed, color, hungry, tired, etc.
▪ Behaviors: eat, sleep, etc.
▪ Car:
▪ Attributes: speed, color, wheel, doors, etc.
▪ Behaviors: move, accelerate, break, take turn, etc.
What is an Object?
▪Examples:
▪ Wheel:
▪ Attributes: color, radius, etc.
▪ Behaviors: rotate, etc.
▪ Bank Account:
▪ Attributes: account number, owner, balance, etc.
▪ Behaviors: withdraw, deposit, etc.
Software Object
▪A representation of real-world objects and processes
▪Object-oriented programming is a methodology that gives
programmers tools to make this modeling process easier
▪Software objects, like real-world objects, have attributes and
behaviors
A real life example
▪Car Racing Game
▪Requirements:
▪In game:
▪ Drive car
▪Inventory:
▪ Change car model
▪ Modify car configuration
▪Solve using structured programming for 9 players?
Car Racing Game with Structured
Programming
Car Racing Game Events
▪Accelerate
▪Break
▪Change wheel color of player 5 to red
▪Player 2 changed his car's wheel to player 7’s
Car Racing Game Events
▪Accelerate:
Car Racing Game Events
▪Break:
Car Racing Game Events
▪Change wheel color of player 5 to red:
Car Racing Game Events
▪Player 2 changed his car's wheel to player 7’s:
Any issues with this solution?
▪Car functions assigned to programmer 1
▪Wheel functions assigned to programmer 2
▪Programmer 3 needs to drive the car taking user input
▪Which variables Programmer 3 need to modify for a particular task?
▪Programmer 3 needs to know internal implementation details
▪No modularization!!
OOP centric design
▪Accelerate
▪Break
▪Change wheel color of player 5 to red
▪Player 2 changed his car's wheel to player 7’s
Why OOP is better here?
▪Can map real world complex objects easily
▪Modularization
▪Internal implementation details are abstracted away
▪Efficient problem solving
THANK YOU