Mid 1 Slide 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

OOP

Introduction
Program ?

Set of Instructions + Data


What’s required?
❑ Accept Input
❑ Store data
❑ Manipulate data
❑ Produce Output
What Computer understands?
At the end of the day...
computers just manipulate 0’s and 1’s
Programming Languages
• Programmers write instructions in various
programming languages
– some directly understandable by computers
– others requiring intermediate translation steps.
• Hundreds of such languages are in use today.
These may be divided into three general types:
o Machine languages
o Assembly languages
o High-level languages
Machine languages
• Any computer can directly understand only its own
machine language, defined by its hardware design.
• Machine languages generally consist of strings of
numbers (ultimately reduced to 1s and 0s) that
instruct computers to perform operations.

Drawbacks
binary is hard (for humans) to
work with.
simply too slow and tedious
for most programmers.
Assembly languages
• English-like abbreviations to represent elementary
operations.
• Translator programs called assemblers were
developed to convert assembly-language programs to
machine language at computer speeds.

Example (C = A + B)
load A Drawbacks
add B Programmers still had to use
store C many instructions to accomplish
even the simplest tasks.
High-level Languages
• Translator programs called compilers convert
high-level language programs into machine
language.
• Allow us to write instructions that look
almost like everyday English and contain
commonly used mathematical notations.
(For example: C = A + B)
Advantages
simpler to write & understand
more library support, data
structures
Compiler vs. Interpreter
• Both Compiler and Interpreter are piece of code that
translates the high level language into machine
language.
• Compiler
– scans the entire program first and then translates it into
machine code which will be executed by the computer
processor.

• Interpreter
– translates every statements it into machine code and which
will be executed by the computer processor one by one.
A Survey of Programming Techniques
• Unstructured programming

• Procedural programming
• Modular programming and
• Object-oriented programming
Unstructured Programming
• Small and simple programs consisting only of one
main program

• Disadvantage:
– The main program directly operates on global data.
– Difficult to manage as the program gets sufficiently large.
Procedural Programming
• Combine sequences
of statements into
one single place
(known as
procedure).
• Program can be
viewed as a sequence
of procedure calls.
Procedural Programming

• The flow of data can


be illustrated as a
hierarchical graph, a
tree.

Disadvantage
1. When changes are made to the main procedure (top),
those changes can cascade to the sub procedures of main,
and the sub-sub procedures and so on, where the change
may impact all procedures.
2. Unrestricted access to global data.
Modular Programming
• Procedures of a common
functionality are grouped
together into separate
modules.
• Divided into several
smaller parts which
interact through procedure
calls and which form the
whole program
• Each module can have its
own data.
Modular Programming
• Advantages
– Make your actual program shorter
– Easier to read and understand
– Make it simpler to figure out how the program
operates
– Reduce the likelihood of bugs
Modular Programming
• Drawbacks
– difficult to relate with the real world objects.
– need more memory space and extra rime for
execution because some modules partly repeat the
task performed by other modules.
– Integration of various modules into a single program
may not be easy because different people working
on design of different modules may not have the
same style.
Object

Object

Object orientation was intended to make thinking


about programming closer the thinking about real
world.
Object
• "An abstraction of something in a problem
domain, reflecting the capabilities of a
system to keep information about it, interact
with it, or both ”

• "An entity able to save a state (information)


and which offers a number of operations
(behaviour) to either examine or affect this
state"
Object
• Real World Object has
– Identity
separate from one another
– Attributes characteristics that describes them
describe current state of objects
– Behaviors
operations
Object
• Real World Object has
– Identity
separate from one another
– Attributes characteristics that describes them
describe current state of objects
– Behaviors
operations
Object Oriented Programming

• OOP is an approach to programming which supports


the creation of new data types and operations to
manipulate those types.
• An object-oriented language breaks a program into
hundreds of tiny entities that have small bits of code
and data fused tightly together.
Procedural vs. OOP

The Old way – What does this program have to do?

The New way – What things are in this program?

You might also like