SlideShare a Scribd company logo
CSC 103 - Object Oriented
     Programming

        Spring, 2011
      Lecture 2, Background


          18th Feb, 2011


    Instructor: M. Anwar-ul-Haq
Imperative Programming
What is Imperative Programming?
• Imperative programming is the type of
  programming you do when you essentially
  just have a list of commands that work
  from the top down to the bottom, and then
  the program is complete.
• This means that it doesn’t have any
  functions or the like.
            OOP, Spring 2011, Engr. Anwar,    2
            Foundation University (FUIEMS),
Imperative Programming
• This type of programming is very
  simplistic, which makes it very difficult,
  time-consuming, and inefficient to do
  complex programs.




              OOP, Spring 2011, Engr. Anwar,    3
              Foundation University (FUIEMS),
Procedural Programming
• What is Procedural Programming?
• Procedural programming is the type of
  programming you do when you make use
  of procedures (yet another synonym for
  functions, processes, and subroutines).




            OOP, Spring 2011, Engr. Anwar,    4
            Foundation University (FUIEMS),
Procedural Programming
• This type of programming is higher-level
  than imperative and allows you to
  accomplish more complex programs.
• However, even procedural programming
  isn’t very effective when it comes to very
  large programs.
• FORTRAN and C are two popular
  procedural programming languages.
             OOP, Spring 2011, Engr. Anwar,    5
             Foundation University (FUIEMS),
Object Oriented Programming
• What is Object-Oriented Programming
  (OOP)?
• Object-oriented programming is the type
  of programming in which you make use of
  objects. Objects are essentially meant to
  be representative of a potentially physical
  object. Objects contain their own data and
  methods (another synonym for functions).

             OOP, Spring 2011, Engr. Anwar,     6
             Foundation University (FUIEMS),
Object Oriented Programming
• Object-oriented programming allows for
  the rapid development of larger scale
  programs.
• Instead of having to have all the
  commands in one location, you can break
  the code down into separate objects.
• This allows for much more manageable
  and readable code, which in turn allows
  for more efficient programming.
            OOP, Spring 2011, Engr. Anwar,    7
            Foundation University (FUIEMS),
Object Oriented Programming
• C++, Java, and PHP are popular object-
  oriented programming languages. You
  could consider JavaScript to be an OOP
  language as well, though it doesn’t make
  use of the typical “class” as others do.




            OOP, Spring 2011, Engr. Anwar,    8
            Foundation University (FUIEMS),
Which is Best?
• OOP programs are best if they meet one
  or more of these criteria:
  – Are fairly large (more than a couple hundred
    lines of code) and will be run on general
    computers.
  – Are fairly complex (more than just output
    simple data).
  – Will be maintained and added to over a period
    of time.
             OOP, Spring 2011, Engr. Anwar,     9
             Foundation University (FUIEMS),
What is Object Oriented
          Programming?
                    • Identifying objects and
                      assigning responsibilities to
                      these objects.
                    • Objects communicate to
An object is like a
                      other objects by sending
  black box.
                      messages.
The internal        • Messages are received by
  details are
                      the methods of an object
  hidden.

                OOP, Spring 2011, Engr. Anwar,        10
                Foundation University (FUIEMS),
What is an object?
•   Tangible Things as a car, printer, ...
•   Roles           as employee, boss, ...
•   Incidents       as flight, overflow, ...
•   Interactions    as contract, sale, ...
•   Specifications   as colour, shape, …




               OOP, Spring 2011, Engr. Anwar,    11
               Foundation University (FUIEMS),
So, what are objects?
• an object represents an individual,
  identifiable item, unit, or entity, either real
  or abstract, with a well-defined role in the
  problem domain.
                Or
• An "object" is anything to which a concept
  applies.
                 etc.

              OOP, Spring 2011, Engr. Anwar,    12
              Foundation University (FUIEMS),
Why do we care about objects?
• Modularity - large software projects
  can be split up in smaller pieces.
• Reusability - Programs can be
  assembled from pre-written software
  components.
• Extensibility - New software
  components can be written or
  developed from existing ones.
            OOP, Spring 2011, Engr. Anwar,    13
            Foundation University (FUIEMS),
What is an Object?
• Real world consists of objects (desk, your
  television set, your bicycle).
• They share two characteristics: They all
  have state and behavior.
• Bicycles have state (current gear, current
  speed) and behavior (changing gear,
  applying brakes).
• Hiding internal state and requiring all
  interaction to be performed through an
  object's methods is known as data
  encapsulation.
             OOP, Spring 2011, Engr. Anwar,    14
             Foundation University (FUIEMS),
Real-World Modeling

• Attributes/State
  – Bicycle: Speed and Gear.
  – People: eye color and job etc.
  – Cars: horsepower and number of doors.

• Behavior: Something a real-world object
  does in response to some stimulus.
  – Bicycle: changeGear, speedUp, applyBrakes
    and printStates.

             OOP, Spring 2011, Engr. Anwar,     15
             Foundation University (FUIEMS),
What Is an Object?
• Grouping code into individual software
  objects provides a number of benefits,
  including:
– Modularity: The source code for an object
  can be written and maintained
  independently of the source code for other
  objects. Once created, an object can be
  easily passed around inside the system.
– Information-hiding: By interacting only with
  an object's methods, the details of its
  internal implementation remain hidden from
  the outside world.
              OOP, Spring 2011, Engr. Anwar,     16
              Foundation University (FUIEMS),
What Is an Object?
– Code re-use: If an object already exists,
  you can use that object in your program.
– Pluggability and debugging ease: If a
  particular object turns out to be
  problematic, you can simply remove it
  from your application and plug in a
  different object as it is.


             OOP, Spring 2011, Engr. Anwar,    17
             Foundation University (FUIEMS),
The two parts of an object
Object = Data (state) + Methods (behaviour)
    or to say the same differently

An object has the responsibility to know and
 the responsibility to do.


            =                                 +
            OOP, Spring 2011, Engr. Anwar,        18
            Foundation University (FUIEMS),
Example
#include <iostream>    void speedUp(int increment)
using namespace std;      {

class Bicycle {                 speed = speed + increment;
private:                    }
    int speed;
    int gear;               void applyBrakes(int decrement)
                            {
public:                          speed = speed - decrement;
   Bicycle()                }
   {
        speed=0;            void printStates()
        gear=0;             {
   }                             cout<<"Speed:"<<speed<<endl;
                                 cout<<"Gear:"<<gear<<endl;
                            }
                       };
Example (contd..)
void main()
{
   Bicycle bike1,bike2;

    bike1.speedUp(10);
    bike1.printStates();

    bike2.speedUp(15);
    bike2.changeGear(12);
    bike2.applyBrakes(5);
    bike2.printStates();

    bike2.speedUp(10);
    bike2.changeGear(3);
    bike2.printStates();
}

More Related Content

PPT
oop Lecture 7
PPT
oop Lecture 10
PPT
oop Lecture19
PPT
oop Lecture 11
PPT
oop Lecture 16
PPT
oop Lecture 3
PPT
Object Oriented Programming lecture 1
PPTX
Object Oriented Programming in Java _lecture 1
oop Lecture 7
oop Lecture 10
oop Lecture19
oop Lecture 11
oop Lecture 16
oop Lecture 3
Object Oriented Programming lecture 1
Object Oriented Programming in Java _lecture 1

What's hot (20)

PPTX
Need of object oriented programming
PPTX
Java object oriented programming concepts - Brainsmartlabs
PPTX
Oop ppt
PPT
Introduction to oop
PPTX
Std 12 computer chapter 6 object oriented concepts (part 1)
PDF
Cs8392 u1-1-oop intro
PPTX
OOP Unit 1 - Foundation of Object- Oriented Programming
PPTX
SKILLWISE - OOPS CONCEPT
PDF
Introduction to oops concepts
PPT
OOP programming
PPTX
Object Oriented Programming Principles
PPTX
1 unit (oops)
PPT
Oops
PPTX
Introduction to oop
PDF
Ah java-ppt2
PPTX
Object oriented programming
PPT
Concepts In Object Oriented Programming Languages
PPTX
Lecture01 object oriented-programming
PPT
Object-Oriented Concepts
PPTX
OOP Unit 2 - Classes and Object
Need of object oriented programming
Java object oriented programming concepts - Brainsmartlabs
Oop ppt
Introduction to oop
Std 12 computer chapter 6 object oriented concepts (part 1)
Cs8392 u1-1-oop intro
OOP Unit 1 - Foundation of Object- Oriented Programming
SKILLWISE - OOPS CONCEPT
Introduction to oops concepts
OOP programming
Object Oriented Programming Principles
1 unit (oops)
Oops
Introduction to oop
Ah java-ppt2
Object oriented programming
Concepts In Object Oriented Programming Languages
Lecture01 object oriented-programming
Object-Oriented Concepts
OOP Unit 2 - Classes and Object
Ad

Similar to Oop lec 2 (20)

PDF
OOP Java
PDF
Sulthan's_JAVA_Material_for_B.Sc-CS.pdf
PPTX
Object Oriented programming - Introduction
PDF
PDF
OOPs-Interview-Questions.pdf
PPT
Need of OOPs and Programming,pop vs oop
PPTX
Lecture 1.1 - Introducing Java.pptx3eeeee
DOCX
Unit1 jaava
PDF
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
PPT
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
PPTX
basics of c++ object oriented programming l anguage
PPTX
introduction to object oriented programming
PDF
6_Object-oriented-using-java.pdf object oriented programming concepts
PPT
Basic concept of OOP's
PDF
Oop basic overview
PPTX
130704798265658191
PPT
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
PPTX
PDF
Object oriented concepts ppt
PPTX
Oop.pptx
OOP Java
Sulthan's_JAVA_Material_for_B.Sc-CS.pdf
Object Oriented programming - Introduction
OOPs-Interview-Questions.pdf
Need of OOPs and Programming,pop vs oop
Lecture 1.1 - Introducing Java.pptx3eeeee
Unit1 jaava
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
basics of c++ object oriented programming l anguage
introduction to object oriented programming
6_Object-oriented-using-java.pdf object oriented programming concepts
Basic concept of OOP's
Oop basic overview
130704798265658191
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
Object oriented concepts ppt
Oop.pptx
Ad

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Cloud computing and distributed systems.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
KodekX | Application Modernization Development
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Cloud computing and distributed systems.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Spectroscopy.pptx food analysis technology
Per capita expenditure prediction using model stacking based on satellite ima...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development
Digital-Transformation-Roadmap-for-Companies.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25 Week I
Building Integrated photovoltaic BIPV_UPV.pdf
sap open course for s4hana steps from ECC to s4
Empathic Computing: Creating Shared Understanding

Oop lec 2

  • 1. CSC 103 - Object Oriented Programming Spring, 2011 Lecture 2, Background 18th Feb, 2011 Instructor: M. Anwar-ul-Haq
  • 2. Imperative Programming What is Imperative Programming? • Imperative programming is the type of programming you do when you essentially just have a list of commands that work from the top down to the bottom, and then the program is complete. • This means that it doesn’t have any functions or the like. OOP, Spring 2011, Engr. Anwar, 2 Foundation University (FUIEMS),
  • 3. Imperative Programming • This type of programming is very simplistic, which makes it very difficult, time-consuming, and inefficient to do complex programs. OOP, Spring 2011, Engr. Anwar, 3 Foundation University (FUIEMS),
  • 4. Procedural Programming • What is Procedural Programming? • Procedural programming is the type of programming you do when you make use of procedures (yet another synonym for functions, processes, and subroutines). OOP, Spring 2011, Engr. Anwar, 4 Foundation University (FUIEMS),
  • 5. Procedural Programming • This type of programming is higher-level than imperative and allows you to accomplish more complex programs. • However, even procedural programming isn’t very effective when it comes to very large programs. • FORTRAN and C are two popular procedural programming languages. OOP, Spring 2011, Engr. Anwar, 5 Foundation University (FUIEMS),
  • 6. Object Oriented Programming • What is Object-Oriented Programming (OOP)? • Object-oriented programming is the type of programming in which you make use of objects. Objects are essentially meant to be representative of a potentially physical object. Objects contain their own data and methods (another synonym for functions). OOP, Spring 2011, Engr. Anwar, 6 Foundation University (FUIEMS),
  • 7. Object Oriented Programming • Object-oriented programming allows for the rapid development of larger scale programs. • Instead of having to have all the commands in one location, you can break the code down into separate objects. • This allows for much more manageable and readable code, which in turn allows for more efficient programming. OOP, Spring 2011, Engr. Anwar, 7 Foundation University (FUIEMS),
  • 8. Object Oriented Programming • C++, Java, and PHP are popular object- oriented programming languages. You could consider JavaScript to be an OOP language as well, though it doesn’t make use of the typical “class” as others do. OOP, Spring 2011, Engr. Anwar, 8 Foundation University (FUIEMS),
  • 9. Which is Best? • OOP programs are best if they meet one or more of these criteria: – Are fairly large (more than a couple hundred lines of code) and will be run on general computers. – Are fairly complex (more than just output simple data). – Will be maintained and added to over a period of time. OOP, Spring 2011, Engr. Anwar, 9 Foundation University (FUIEMS),
  • 10. What is Object Oriented Programming? • Identifying objects and assigning responsibilities to these objects. • Objects communicate to An object is like a other objects by sending black box. messages. The internal • Messages are received by details are the methods of an object hidden. OOP, Spring 2011, Engr. Anwar, 10 Foundation University (FUIEMS),
  • 11. What is an object? • Tangible Things as a car, printer, ... • Roles as employee, boss, ... • Incidents as flight, overflow, ... • Interactions as contract, sale, ... • Specifications as colour, shape, … OOP, Spring 2011, Engr. Anwar, 11 Foundation University (FUIEMS),
  • 12. So, what are objects? • an object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain. Or • An "object" is anything to which a concept applies. etc. OOP, Spring 2011, Engr. Anwar, 12 Foundation University (FUIEMS),
  • 13. Why do we care about objects? • Modularity - large software projects can be split up in smaller pieces. • Reusability - Programs can be assembled from pre-written software components. • Extensibility - New software components can be written or developed from existing ones. OOP, Spring 2011, Engr. Anwar, 13 Foundation University (FUIEMS),
  • 14. What is an Object? • Real world consists of objects (desk, your television set, your bicycle). • They share two characteristics: They all have state and behavior. • Bicycles have state (current gear, current speed) and behavior (changing gear, applying brakes). • Hiding internal state and requiring all interaction to be performed through an object's methods is known as data encapsulation. OOP, Spring 2011, Engr. Anwar, 14 Foundation University (FUIEMS),
  • 15. Real-World Modeling • Attributes/State – Bicycle: Speed and Gear. – People: eye color and job etc. – Cars: horsepower and number of doors. • Behavior: Something a real-world object does in response to some stimulus. – Bicycle: changeGear, speedUp, applyBrakes and printStates. OOP, Spring 2011, Engr. Anwar, 15 Foundation University (FUIEMS),
  • 16. What Is an Object? • Grouping code into individual software objects provides a number of benefits, including: – Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system. – Information-hiding: By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world. OOP, Spring 2011, Engr. Anwar, 16 Foundation University (FUIEMS),
  • 17. What Is an Object? – Code re-use: If an object already exists, you can use that object in your program. – Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as it is. OOP, Spring 2011, Engr. Anwar, 17 Foundation University (FUIEMS),
  • 18. The two parts of an object Object = Data (state) + Methods (behaviour) or to say the same differently An object has the responsibility to know and the responsibility to do. = + OOP, Spring 2011, Engr. Anwar, 18 Foundation University (FUIEMS),
  • 19. Example #include <iostream> void speedUp(int increment) using namespace std; { class Bicycle { speed = speed + increment; private: } int speed; int gear; void applyBrakes(int decrement) { public: speed = speed - decrement; Bicycle() } { speed=0; void printStates() gear=0; { } cout<<"Speed:"<<speed<<endl; cout<<"Gear:"<<gear<<endl; } };
  • 20. Example (contd..) void main() { Bicycle bike1,bike2; bike1.speedUp(10); bike1.printStates(); bike2.speedUp(15); bike2.changeGear(12); bike2.applyBrakes(5); bike2.printStates(); bike2.speedUp(10); bike2.changeGear(3); bike2.printStates(); }