Concepts of Object Oriented Programming
LECTURE # 1
Why Do We Need Object-Oriented
Programming?
Object-Oriented Programming was developed because limitations were
discovered in earlier approaches to programming. To appreciate what
OOP does, we need to understand what these limitations are and how
they arose from traditional programming languages.
ProceduralLanguages
oC, Pascal, FORTRAN, and similar languages are procedural
languages. That is, each statement in the language tells the
computer to do something: Get some input, add these numbers,
divide by 6, display that output.
o A program in a procedural language is a list of instructions.
oFor very small programs, no other organizing principle (often
called a paradigm) is needed. The programmer creates the list of
instructions, and the computer carries them out.
Procedural vs. Object-Oriented
Programming
The unit in procedural programming is function, and unit in object-
oriented programming is class
Procedural programming concentrates on creating functions, while
object-oriented programming starts from isolating the classes, and then
look for the methods inside them.
Procedural programming separates the data of the program from the
operations that manipulate the data, while object-oriented
programming focus on both of them
What does OOP mean?
Object-oriented programming (OOP) is a software programming model
constructed around objects. This model compartmentalizes data into
objects (data fields) and describes object contents and behavior
through the declaration of classes (methods).
Object
An Object is a software entity that models something in the real world.
It has two main properties:
◦ State: the object encapsulates information about itself - attributes
or fields.
◦ Behaviour: the object can do some things on behalf of other objects
– methods
Example: In a banking system, a particular bank account is an example
of an object.
◦ Its state consists of attributes like: owner, account number, balance,
etc.
◦ Its behaviours consist of: deposit, withdraw, etc.
Object
Other examples of objects are:
◦ myself – an instructor object. What are my fields and methods?
◦ you – a student object
◦ this room – a room object
◦ this university
◦ your car, etc.
In an object-oriented system, objects are created from something called
a Class, so next we need to know what a class is.
Class
Class is a like a Blueprint.
What is a blueprint?
Blueprint is outline drawing of our actual plan. For example if we plan to
build our new home ,The Engineer will explain our new house plan with
a blue print as shown in the image below. Once we finalized the plan
the engineer will start building the house with same plan.
Class
A class is a general, abstract representation of an object, that
specifies the fields and methods that such an object has.
When we write OO programs we don't define individual objects,
we define classes, and then use them as templates for
constructing objects. Each individual object is called an instance
of its class.
For example, you might have a Tree class that describes the
features of all trees (each tree has branches and roots, grows,
etc.).
Class
Of course, once you have a Tree class, you can create lots of different
instances of that tree, and each different tree instance can have different
features (it can be short, tall, bushy, have fruits, etc.), yet still behave like a
tree and can be recognized as one
Design Principles of OOP
Four main design principles of Object-Oriented Programming(OOP):
Encapsulation
Abstraction
Polymorphism
Inheritance
Encapsulation
Also known as data hiding
Only object’s methods can modify information in the object.
This makes the program structure easier to manage because each
object’s implementation and state are hidden behind well-defined
boundaries.
Abstraction
"To represent the essential feature without representing the
background details."Abstraction lets you focus on what the object does
instead of how it does it.
Polymorphism
This means abstract entities are implemented in multiple ways.
the same word or phrase can mean different things in different
contexts
Analogy:
In English, bank can mean side of a river or a place to put money
Inheritance
This refers to the hierarchical arrangement of implementation
fragments.
Term comes from inheritance of traits like eye color, hair color, and so
on.
Classes with properties in common can be grouped so that their
common properties are only defined once.
yo.pptxoajsdisa odasjd asodjaojdoawjdoasjdow

yo.pptxoajsdisa odasjd asodjaojdoawjdoasjdow

  • 1.
    Concepts of ObjectOriented Programming LECTURE # 1
  • 2.
    Why Do WeNeed Object-Oriented Programming? Object-Oriented Programming was developed because limitations were discovered in earlier approaches to programming. To appreciate what OOP does, we need to understand what these limitations are and how they arose from traditional programming languages.
  • 3.
    ProceduralLanguages oC, Pascal, FORTRAN,and similar languages are procedural languages. That is, each statement in the language tells the computer to do something: Get some input, add these numbers, divide by 6, display that output. o A program in a procedural language is a list of instructions. oFor very small programs, no other organizing principle (often called a paradigm) is needed. The programmer creates the list of instructions, and the computer carries them out.
  • 4.
    Procedural vs. Object-Oriented Programming Theunit in procedural programming is function, and unit in object- oriented programming is class Procedural programming concentrates on creating functions, while object-oriented programming starts from isolating the classes, and then look for the methods inside them. Procedural programming separates the data of the program from the operations that manipulate the data, while object-oriented programming focus on both of them
  • 5.
    What does OOPmean? Object-oriented programming (OOP) is a software programming model constructed around objects. This model compartmentalizes data into objects (data fields) and describes object contents and behavior through the declaration of classes (methods).
  • 6.
    Object An Object isa software entity that models something in the real world. It has two main properties: ◦ State: the object encapsulates information about itself - attributes or fields. ◦ Behaviour: the object can do some things on behalf of other objects – methods Example: In a banking system, a particular bank account is an example of an object. ◦ Its state consists of attributes like: owner, account number, balance, etc. ◦ Its behaviours consist of: deposit, withdraw, etc.
  • 7.
    Object Other examples ofobjects are: ◦ myself – an instructor object. What are my fields and methods? ◦ you – a student object ◦ this room – a room object ◦ this university ◦ your car, etc. In an object-oriented system, objects are created from something called a Class, so next we need to know what a class is.
  • 8.
    Class Class is alike a Blueprint. What is a blueprint? Blueprint is outline drawing of our actual plan. For example if we plan to build our new home ,The Engineer will explain our new house plan with a blue print as shown in the image below. Once we finalized the plan the engineer will start building the house with same plan.
  • 9.
    Class A class isa general, abstract representation of an object, that specifies the fields and methods that such an object has. When we write OO programs we don't define individual objects, we define classes, and then use them as templates for constructing objects. Each individual object is called an instance of its class. For example, you might have a Tree class that describes the features of all trees (each tree has branches and roots, grows, etc.).
  • 10.
    Class Of course, onceyou have a Tree class, you can create lots of different instances of that tree, and each different tree instance can have different features (it can be short, tall, bushy, have fruits, etc.), yet still behave like a tree and can be recognized as one
  • 11.
    Design Principles ofOOP Four main design principles of Object-Oriented Programming(OOP): Encapsulation Abstraction Polymorphism Inheritance
  • 12.
    Encapsulation Also known asdata hiding Only object’s methods can modify information in the object. This makes the program structure easier to manage because each object’s implementation and state are hidden behind well-defined boundaries.
  • 14.
    Abstraction "To represent theessential feature without representing the background details."Abstraction lets you focus on what the object does instead of how it does it.
  • 16.
    Polymorphism This means abstractentities are implemented in multiple ways. the same word or phrase can mean different things in different contexts Analogy: In English, bank can mean side of a river or a place to put money
  • 17.
    Inheritance This refers tothe hierarchical arrangement of implementation fragments. Term comes from inheritance of traits like eye color, hair color, and so on. Classes with properties in common can be grouped so that their common properties are only defined once.