CSC 103 - Object Oriented     Programming        Spring, 2011      Lecture 2, Background          18th Feb, 2011    Instru...
Imperative ProgrammingWhat is Imperative Programming?• Imperative programming is the type of  programming you do when you ...
Imperative Programming• This type of programming is very  simplistic, which makes it very difficult,  time-consuming, and ...
Procedural Programming• What is Procedural Programming?• Procedural programming is the type of  programming you do when yo...
Procedural Programming• This type of programming is higher-level  than imperative and allows you to  accomplish more compl...
Object Oriented Programming• What is Object-Oriented Programming  (OOP)?• Object-oriented programming is the type  of prog...
Object Oriented Programming• Object-oriented programming allows for  the rapid development of larger scale  programs.• Ins...
Object Oriented Programming• C++, Java, and PHP are popular object-  oriented programming languages. You  could consider J...
Which is Best?• OOP programs are best if they meet one  or more of these criteria:  – Are fairly large (more than a couple...
What is Object Oriented          Programming?                    • Identifying objects and                      assigning ...
What is an object?•   Tangible Things as a car, printer, ...•   Roles           as employee, boss, ...•   Incidents       ...
So, what are objects?• an object represents an individual,  identifiable item, unit, or entity, either real  or abstract, ...
Why do we care about objects?• Modularity - large software projects  can be split up in smaller pieces.• Reusability - Pro...
What is an Object?• Real world consists of objects (desk, your  television set, your bicycle).• They share two characteris...
Real-World Modeling• Attributes/State  – Bicycle: Speed and Gear.  – People: eye color and job etc.  – Cars: horsepower an...
What Is an Object?• Grouping code into individual software  objects provides a number of benefits,  including:– Modularity...
What Is an Object?– Code re-use: If an object already exists,  you can use that object in your program.– Pluggability and ...
The two parts of an objectObject = Data (state) + Methods (behaviour)    or to say the same differentlyAn object has the r...
Example#include <iostream>    void speedUp(int increment)using namespace std;      {class Bicycle {                 speed ...
Example (contd..)void main(){   Bicycle bike1,bike2;    bike1.speedUp(10);    bike1.printStates();    bike2.speedUp(15);  ...
Upcoming SlideShare
Loading in …5
×

Oop lec 2

1,099 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,099
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
38
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Oop lec 2

  1. 1. CSC 103 - Object Oriented Programming Spring, 2011 Lecture 2, Background 18th Feb, 2011 Instructor: M. Anwar-ul-Haq
  2. 2. Imperative ProgrammingWhat 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. 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. 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. 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. 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. 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. 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. 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. 10. What is Object Oriented Programming? • Identifying objects and assigning responsibilities to these objects. • Objects communicate toAn 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. 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. 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. 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. 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 objects methods is known as data encapsulation. OOP, Spring 2011, Engr. Anwar, 14 Foundation University (FUIEMS),
  15. 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. 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 objects methods, the details of its internal implementation remain hidden from the outside world. OOP, Spring 2011, Engr. Anwar, 16 Foundation University (FUIEMS),
  17. 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. 18. The two parts of an objectObject = Data (state) + Methods (behaviour) or to say the same differentlyAn object has the responsibility to know and the responsibility to do. = + OOP, Spring 2011, Engr. Anwar, 18 Foundation University (FUIEMS),
  19. 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. 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();}

×