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

What's hot

Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
Amar Jukuntla
 
Java object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - BrainsmartlabsJava object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - Brainsmartlabs
brainsmartlabsedu
 
Oop ppt
Oop pptOop ppt
Oop ppt
Shani Manjara
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop Kumar
 
Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)
Nuzhat Memon
 
Cs8392 u1-1-oop intro
Cs8392 u1-1-oop introCs8392 u1-1-oop intro
Cs8392 u1-1-oop intro
Rajasekaran S
 
OOP Unit 1 - Foundation of Object- Oriented Programming
OOP Unit 1 - Foundation of Object- Oriented ProgrammingOOP Unit 1 - Foundation of Object- Oriented Programming
OOP Unit 1 - Foundation of Object- Oriented Programming
dkpawar
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh Dalvi
 
Object Oriented Programming : A Brief History and its significance
Object Oriented Programming : A Brief History and its significanceObject Oriented Programming : A Brief History and its significance
Object Oriented Programming : A Brief History and its significance
Gajesh Bhat
 
OOP programming
OOP programmingOOP programming
OOP programminganhdbh
 
Object Oriented Programming Principles
Object Oriented Programming PrinciplesObject Oriented Programming Principles
Object Oriented Programming Principles
Andrew Ferlitsch
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)Jay Patel
 
Oops
OopsOops
Oops
Prabhu R
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
colleges
 
Ah java-ppt2
Ah java-ppt2Ah java-ppt2
Ah java-ppt2
Haja Abdul Khader A
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Amit Soni (CTFL)
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languages
ppd1961
 
Lecture01 object oriented-programming
Lecture01 object oriented-programmingLecture01 object oriented-programming
Lecture01 object oriented-programmingHariz Mustafa
 
Object-Oriented Concepts
Object-Oriented ConceptsObject-Oriented Concepts
Object-Oriented ConceptsAbdalla Mahmoud
 

What's hot (20)

Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
Java object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - BrainsmartlabsJava object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - Brainsmartlabs
 
Oop ppt
Oop pptOop ppt
Oop ppt
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 
Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)
 
Cs8392 u1-1-oop intro
Cs8392 u1-1-oop introCs8392 u1-1-oop intro
Cs8392 u1-1-oop intro
 
OOP Unit 1 - Foundation of Object- Oriented Programming
OOP Unit 1 - Foundation of Object- Oriented ProgrammingOOP Unit 1 - Foundation of Object- Oriented Programming
OOP Unit 1 - Foundation of Object- Oriented Programming
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 
Object Oriented Programming : A Brief History and its significance
Object Oriented Programming : A Brief History and its significanceObject Oriented Programming : A Brief History and its significance
Object Oriented Programming : A Brief History and its significance
 
OOP programming
OOP programmingOOP programming
OOP programming
 
Object Oriented Programming Principles
Object Oriented Programming PrinciplesObject Oriented Programming Principles
Object Oriented Programming Principles
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
Oops
OopsOops
Oops
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Ah java-ppt2
Ah java-ppt2Ah java-ppt2
Ah java-ppt2
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languages
 
Lecture01 object oriented-programming
Lecture01 object oriented-programmingLecture01 object oriented-programming
Lecture01 object oriented-programming
 
Object-Oriented Concepts
Object-Oriented ConceptsObject-Oriented Concepts
Object-Oriented Concepts
 

Similar to Oop lec 2

OOP Java
OOP JavaOOP Java
OOP Java
Saif Kassim
 
Sulthan's_JAVA_Material_for_B.Sc-CS.pdf
Sulthan's_JAVA_Material_for_B.Sc-CS.pdfSulthan's_JAVA_Material_for_B.Sc-CS.pdf
Sulthan's_JAVA_Material_for_B.Sc-CS.pdf
SULTHAN BASHA
 
Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - Introduction
Madishetty Prathibha
 
OOPs-Interview-Questions.pdf
OOPs-Interview-Questions.pdfOOPs-Interview-Questions.pdf
OOPs-Interview-Questions.pdf
Samir Paul
 
Need of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oopNeed of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oop
Janani Selvaraj
 
Unit1 jaava
Unit1 jaavaUnit1 jaava
Unit1 jaavamrecedu
 
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
CS3391 -OOP -UNIT – I  NOTES FINAL.pdfCS3391 -OOP -UNIT – I  NOTES FINAL.pdf
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
sagarjsicg
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
Prof. Dr. K. Adisesha
 
Oop basic overview
Oop basic overviewOop basic overview
Oop basic overview
Deborah Akuoko
 
130704798265658191
130704798265658191130704798265658191
130704798265658191
Tanzeel Ahmad
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Object oriented concepts ppt
Object oriented concepts pptObject oriented concepts ppt
Object oriented concepts ppt
Prof. Dr. K. Adisesha
 
Oop.pptx
Oop.pptxOop.pptx
Oop.pptx
KalGetachew2
 
C++ notes.pdf
C++ notes.pdfC++ notes.pdf
C++ notes.pdf
RajanBagale3
 
introduction of Object oriented programming
introduction of Object oriented programmingintroduction of Object oriented programming
introduction of Object oriented programming
RiturajJain8
 
object oriented programming(oops)
object oriented programming(oops)object oriented programming(oops)
object oriented programming(oops)
HANISHTHARWANI21BCE1
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
siragezeynu
 
oops.pdf
oops.pdfoops.pdf

Similar to Oop lec 2 (20)

OOP Java
OOP JavaOOP Java
OOP Java
 
Sulthan's_JAVA_Material_for_B.Sc-CS.pdf
Sulthan's_JAVA_Material_for_B.Sc-CS.pdfSulthan's_JAVA_Material_for_B.Sc-CS.pdf
Sulthan's_JAVA_Material_for_B.Sc-CS.pdf
 
Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - Introduction
 
OOPs-Interview-Questions.pdf
OOPs-Interview-Questions.pdfOOPs-Interview-Questions.pdf
OOPs-Interview-Questions.pdf
 
Oop's
Oop'sOop's
Oop's
 
Need of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oopNeed of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oop
 
Unit1 jaava
Unit1 jaavaUnit1 jaava
Unit1 jaava
 
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
CS3391 -OOP -UNIT – I  NOTES FINAL.pdfCS3391 -OOP -UNIT – I  NOTES FINAL.pdf
CS3391 -OOP -UNIT – I NOTES FINAL.pdf
 
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
1. OBJECT ORIENTED PROGRAMMING USING JAVA - OOps Concepts.ppt
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Oop basic overview
Oop basic overviewOop basic overview
Oop basic overview
 
130704798265658191
130704798265658191130704798265658191
130704798265658191
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Object oriented concepts ppt
Object oriented concepts pptObject oriented concepts ppt
Object oriented concepts ppt
 
Oop.pptx
Oop.pptxOop.pptx
Oop.pptx
 
C++ notes.pdf
C++ notes.pdfC++ notes.pdf
C++ notes.pdf
 
introduction of Object oriented programming
introduction of Object oriented programmingintroduction of Object oriented programming
introduction of Object oriented programming
 
object oriented programming(oops)
object oriented programming(oops)object oriented programming(oops)
object oriented programming(oops)
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
oops.pdf
oops.pdfoops.pdf
oops.pdf
 

Recently uploaded

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 

Recently uploaded (20)

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 

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(); }