12. Objects I

203 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
203
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

12. Objects I

  1. 1. From last time… • We discussed Iteration 1 expectations! • Functions:! ! - DRY: Don’t Repeat Yourself! ! - How to “read” a function definition! ! - Type & number of arguments must match! ! - Arguments are passed by copy into functions! • Reviewed Quiz 2: Variables, Conditionals, Loops
  2. 2. “All programming languages ! are exactly the same.” Prof. Angelos Barmpoutis! University of Florida
  3. 3. Programming Languages vs. Natural Languages Variables, Operations, Logical Operators Sounds, Words Functions Sentences Conditional Statements Paragraphs Objects Chapters, Entire Books
  4. 4. Objects I CAP
  5. 5. Object-Oriented Programming • OOP is a programming paradigm! • It a mental model for thinking about code! • It informs the organization & structure of code! • Object-oriented code is organized into “objects” that interact with each other
  6. 6. c++ c# smalltalk ruby php java objective-c python perl
  7. 7. What do we know so far… Data! variables – store data: int, boolean, float, etc.! operations – manipulate data: + - / *! logical operators – compare data: > < >= <= ==! Functionality! functions – simple behavior: size(), fill() loops – repeated behavior: for (int i = 0; i < 100; i++)! conditionals – flow control: if (conditional) {} else {}
  8. 8. Objects • It makes sense to organize related data and functionality into one thing! • We call this thing an ‘object’! • Any thing in the world could be viewed as an object—as a grouping of data and functionality
  9. 9. Object-Oriented Thinking • An Animal! • A Human! • A Vehicle! • A Celestial Body… and Gravity! • An Email… An Inbox… and An Email Application! • In programming, objects are defined by classes
  10. 10. Class Anatomy Name Class! Blueprint! Cookie Cutter! Mould Data What is the class called? What are its attributes?! What state is currently it in? Constructor When I create a new one,! what do I need to do? Functionality What actions can it take?! What does it do?
  11. 11. Class Anatomy Name Class! Blueprint! Cookie Cutter! Mould Data Constructor Functionality Vehicle String type; // e.g.,“Car” float price; // e.g., 7825 Vehicle(type, price) moveForward(); moveBackward(); honk(); Notice that a class is a generic blueprint–a container.! It has placeholders for data, and defines functionality.
  12. 12. Classes make Objects Class! Object! Object! Object! Vehicle! Vehicle! Vehicle! Vehicle! ! ! ! ! ! String type! float price “Car”! 2374.72 “Car”! 4255.95 “Airplane”! 400000 These are instances of the Vehicle Class
  13. 13. Demo! A Star Class
  14. 14. Remember… A class must have 4 things:! 1. a name! 2. attributes (variables)! 3. a constructor (run once, when we use new)! 4. methods (functions)! Learn and memorize how to make code into classes!
  15. 15. “All programming languages ! are exactly the same.” Prof. Angelos Barmpoutis! University of Florida
  16. 16. Unified Modeling Language UML defines a consistent method for diagramming a class. This is what a “Class Diagram” looks like: Name! ! Variables! ! ! Methods
  17. 17. Class Diagram Example Email Inbox MailManager to from subject body name emails inboxes displayEmail orderEmailsByAlpha orderEmailsByDate displayInbox createEmail sendEmail checkEmail
  18. 18. For next time… • Read Shiffman, p. 130–137 (Objects II)! • Keep working on Iteration 1

×