1 / 18

Lesson 25 The object-oriented thought process

Lesson 25 The object-oriented thought process. Python Mini-Course University of Oklahoma Department of Psychology . Lesson objectives. Define the key terms used in object-oriented programming (OOP) Understand the difference between an object and a class

serafina
Télécharger la présentation

Lesson 25 The object-oriented thought process

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. Lesson 25The object-oriented thought process Python Mini-Course University of Oklahoma Department of Psychology Python Mini-Course: Lesson 25

  2. Lesson objectives • Define the key terms used in object-oriented programming (OOP) • Understand the difference between an object and a class • Describe the types of relationships that are possible between objects Python Mini-Course: Lesson 25

  3. Procedural vs. OOP • Review from Lesson 6 • Procedural programming separates the program operations and the data • Object-oriented programming packages the program operations and the data together in object Python Mini-Course: Lesson 25

  4. What is an object? • The building blocks of an O-O program • A program that uses O-O is basically a collection of objects • Objects interact much like things in the real world do Python Mini-Course: Lesson 25

  5. What is an object? • Objects have two components: • Data (i.e., attributes) • Behaviors (i.e., methods) Python Mini-Course: Lesson 25

  6. Object attributes • Store the data for that object • Example (taxi): • Driver • OnDuty • NumPassengers • Location Python Mini-Course: Lesson 25

  7. Object methods • Define the behaviors for the object • Example (taxi): • PickUp • DropOff • GoOnDuty • GoOffDuty • GetDriver • SetDriver • GetNumPassengers Python Mini-Course: Lesson 25

  8. Object interface • To use a method, the user (programmer) must know: • Name of the method • Parameters to pass to the method • What (if anything) the method returns Python Mini-Course: Lesson 25

  9. Object implementation • The user does NOT need to know how the method works internally Python Mini-Course: Lesson 25

  10. What is a Class? • A blueprint for an object • Classes can be thought of as templates or cookie cutters • Given a class description, we can instantiate objects of that class • Classes are high-level data types Python Mini-Course: Lesson 25

  11. OOP concepts • Encapsulation • Data and behaviors are packaged together, but the object only reveals the interfaces needed to interact with it • Internal data and behaviors can remain hidden Python Mini-Course: Lesson 25

  12. OOP concepts • Interfaces • Fundamental means of communication between objects • Should completely describe to user (programmer) how to interact with the object • Should control access to attributes Python Mini-Course: Lesson 25

  13. Inheritance • You can create new classes by abstracting out common attributes and behaviors from a parent (or base) class Python Mini-Course: Lesson 25

  14. Python Mini-Course: Lesson 25

  15. Is-a relationship • Because sub-classes inherit from their base class, they have an is-a relationship: • Lion is a cat • Cat is a mammal Python Mini-Course: Lesson 25

  16. Polymorphism • Allows similar objects to to respond to the same message (method call) in different manners • Sub-classes can override base class methods Python Mini-Course: Lesson 25

  17. OOP example: animals.py class Animal: def __init__(self, name): # Constructor of the class self.name = name class Cat(Animal): def talk(self): return 'Meow!' class Dog(Animal): def talk(self): return 'Woof! Woof!' Python Mini-Course: Lesson 25

  18. Composition • Objects can contain other objects • This is called a has-a relationship • Example: • Taxi has-a driver Python Mini-Course: Lesson 25

More Related