CSC 203 chapter 10: Object-Oriented Programming

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/23

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

24 Terms

1
New cards

object-based programming

primarily create and use objects of existing classes

2
New cards

Classes

new data types

3
New cards

When creating a new class, instead of writing all new code, you can

designate that the new class is to be formed initially by inheriting the attributes (variables) and methods (the class version of functions) of a previously defined base class (also called a superclass). The new class is called a derived class (or subclass). After inheriting, you then customize the derived class to meet the specific needs of your application

4
New cards

base class or a superclass

a previously defined base class

5
New cards

derived class or a subclass

new class

6
New cards

inheritance

allows a class (called a child or derived class) to inherit attributes and methods from another class (called a parent or base class)

7
New cards

polymorphism

enables you to conveniently program “in the general” rather than “in the specific.” You simply send the same method call to objects possibly of many different types

8
New cards

Each new class you create becomes

a new data type that can be used to create objects

9
New cards

from file import Class

use the import command followed by the module name and then the class name

10
New cards

constructor expression

it builds and initializes an object of the class. create new objects and initialize their data using argument(s) specified in parentheses

11
New cards

class.attribute

access the class object’s attributes

12
New cards

class header

A class definition begins with the keyword class followed by the class’s name and a colon (:). The Style Guide for Python Code recommends that you begin each word in a multi-word class name with an uppercase letter

13
New cards

To view any class’s docstring in IPython, type the

class name and a question mark, then press Enter

14
New cards

docstring

Each class typically provides this. When provided, it must appear in the line or lines immediately following the class header

15
New cards

def init(self, attributeparameter)

Each new class you create can provide an __ method that specifies how to initialize an object’s data attributes

16
New cards

Returning a value other than None from __init__ results in a

TypeError. Recall that None is returned by any function or method that does not contain a return statement

17
New cards

When you call a method for a specific object, Python implicitly passes a

reference to that object as the method’s first argument. For this reason, all methods of a class must specify at least one parameter

18
New cards

By convention most Python programmers call a method’s first parameter

self. A class’s methods must use that reference (self) to access the object’s attributes and other methods

19
New cards

self.attribute_name = value

A class's attributes are added dynamically via assignments of this form

20
New cards

Unlike class methods, what cannot validate the values you assign to them?

data attributes

21
New cards

Such data in these languages is said to be private data

code that uses objects of the class.

22
New cards

encapsulate

hide an object’s data from the client code. This creates private data, which Python doesn't have. Instead, you use naming conventions to design classes that encourage correct use

23
New cards

any attribute name beginning with an underscore (_) is for a

class’s internal use only

24
New cards

Attributes whose identifiers do not begin with an underscore (_) are considered

publicly accessible for use in client code