1 / 18

Understanding Objects and Classes

Understanding Objects and Classes. Barb Ericson ericson@cc.gatech.edu Jan 2005. Learning Goals. What does object-oriented mean? What are objects? What are classes? Exercises for conceptually understanding objects and classes Scenarios Role-playing. What is Object-Oriented?.

Download Presentation

Understanding Objects and Classes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Understanding Objects and Classes Barb Ericson ericson@cc.gatech.edu Jan 2005 Georgia Institute of Technology

  2. Learning Goals • What does object-oriented mean? • What are objects? • What are classes? • Exercises for conceptually understanding objects and classes • Scenarios • Role-playing Georgia Institute of Technology

  3. What is Object-Oriented? • This means that we focus on the objects not just the procedures • Focus on • who (what objects?) • as well as • what (what do the objects do?) Georgia Institute of Technology

  4. What is an Object? • A person, place, or thing • That knows something about itself • Has data (attributes, fields) • A cashier has a id, name, and a password • And can do something • Has operations (methods) • A cashier can total the items, take payment, make change Georgia Institute of Technology

  5. What is a Class? • The type of an object • The way we classify an object • “The Idiot” by Dostoevsky is a book • “War and Peace” by Tolstoy is a book • Mary is a cashier • Tasha is a cashier • Grouping of objects with the same data and operations Georgia Institute of Technology

  6. Class: Example • Mary is a cashier • Tasha is a cashier • Cashier is a class • All cashiers have an id, name and password • Each will have a different id, name, and password • All cashiers can total an order, take payment, make change Georgia Institute of Technology

  7. Object Data • Each object has its own data • Tasha’s id is 4 and password is mhall • Mary’s id is 3 and password is smile4 • All cashier objects have an id, name, and password • Changing Mary’s data won’t affect Tasha’s data Georgia Institute of Technology

  8. Understanding Objects and Classes • What “types” of objects are in the classroom? • What data is known about each type and what operations can objects of that type do? • Are there several objects of the same “type”. • How are they the same and how different? Georgia Institute of Technology

  9. Simulation • Object-oriented development means creating a simulation of the problem • We need to know the objects in the problem • So we can create software objects to represent them Georgia Institute of Technology

  10. Classes Define the Objects • The computer doesn’t know what we mean by a car or cashier • We define the class Cashier so that the computer will understand what a cashier or bank account “is” and what it can “do” • In the context of the problem we are trying to solve • Then the computer can create objects to do the simulation Georgia Institute of Technology

  11. Classes Create Objects • The class can be thought of as a recipe, blueprint, or factory • Many objects can be created from one class • Objects keep track of the class that created them • I am an object (instance) of the Cookie class Georgia Institute of Technology

  12. Software Objects are Models • The objects we create in software are models of the physical object • We can’t stick a person in our software • We can create a model of the person with the information we need to know for that person for our task Cashier id name password Georgia Institute of Technology

  13. Using Scenarios to Identify Objects • What objects are involved in going to the doctor because you are sick? • What objects are involved in going to the movies? • What objects are involved in a card game like blackjack? Georgia Institute of Technology

  14. Objects have Responsibilities • An object-oriented design • Determines the tasks to be done • Determines what objects will be responsible for each task • No one object does everything • Objects work together to accomplish tasks • The assignment of responsibilities is the key skill in object-oriented design Georgia Institute of Technology

  15. Identifying Classes • What type of thing was each thing in the scenario? How would you classify it? • Patient, Doctor, Nurse, Insurance … • Movie, Ticket Seller, Ticket Taker, Ticket, Popcorn, Drink … • Card, Deck, Player, Suit … • How many objects of that types were in each scenario? • What data did each object have associated with it? What could it do? Georgia Institute of Technology

  16. Learning about Objects and Classes • Walk through scenarios • Do role-playing • Underline nouns in scenarios to identify the objects and classes • Create CRC cards • Draw UML diagrams • Write methods and classes • Specialize a parent class • Use a debugger to step through execution Georgia Institute of Technology

  17. Role Playing Exercises • Page at http://web.sbu.edu/cs/dlevine/RolePlay/roleplay.html has links to exercises • Powerpoint slides you can hand out developed by Joseph Bergin of Pace University • FirstDayRolePlay-Bergin.ppt Georgia Institute of Technology

  18. Summary • Object-oriented programs are simulations • Objects simulate the “real world” and interact to accomplish a task • Classes define the data all objects will have and what things they can do • Ways to start understanding Objects and Classes • Scenarios • Role-Playing Georgia Institute of Technology

More Related