Chapter 10 Flashcards

1
Q

What is an object?

A

An object is a software entity that contains both data and procedures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is encapsulation?

A

Encapsulation is the combining of data and code into a single object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is an object’s internal data usually hidden from outside code?

A

The data is protected from accidental corruption.

In addition, the programming code outside the object does not need to know about the format or internal structure of the object’s data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are public methods? What are private methods?

A

Public methods can be accessed by entities outside the object.

Private methods cannot be accessed by entities outside the object. They are designed to be accessed internally.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You hear someone make the following comment: “A blueprint is a design for a house. A carpenter can use the blueprint to build the house. If the carpenter wishes, he or she can build several identical houses from the same blueprint.” Think of this as a metaphor for classes and objects. Does the blueprint represent a class, or does it represent an object?

A

The metaphor of a blueprint represents a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In this chapter, we use the metaphor of a cookie cutter and cookies that are made from the cookie cutter to describe classes and objects. In this metaphor, are objects the cookie cutter, or the cookies?

A

Objects are the cookies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of the _ init _ method? When does it execute?

A

Its purpose is to initialize an object’s data attributes. It executes immediately after the object is created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of the self parameter in a method?

A

When a method executes, it must have a way of knowing which object’s data attributes it is supposed to operate on. That’s where the self parameter comes in. When a method is called, Python automatically makes its self parameter reference the specific object that the method is supposed to operate on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In a Python class, how do you hide an attribute from code outside the class?

A

By starting the attribute’s name with two underscores

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of the _ str _ method?

A

It returns a string representation of the object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you call the _ str _ method?

A

By passing the object to the built-in str method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an instance attribute?

A

An attribute that belongs to a specific instance of a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A program creates 10 instances of the Coin class. How many _ _sideup attributes exist in memory?

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is an accessor method? What is a mutator method?

A

Accessor method (getter) returns a value from a class’s attribute but does not change it

Mutator method(setter) stores a value in a data attribute or changes the value of a data attribute in some other way

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The typical UML diagram for a class has three sections. What appears in these three sections?

A

The top section is where you write the name of the class.
The middle section holds a list of the class’s fields.
The bottom section holds a list of the class’s methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a problem domain?

A

A written description of the real-world objects, parties, and major events related to the problem

17
Q

When designing an object-oriented application, who should write a description of the problem domain?

A

yourself or an expert

18
Q

How do you identify the potential classes in a problem domain description?

A

First, identify the nouns, pronouns, and pronoun phrases in the problem domain description. Then, refine the list to eliminate duplicates, items that you do not need to be concerned with in the problem, items that represent objects instead of classes, and items that represent simple values that can be stored in variables.

19
Q

What are a class’s responsibilities?

A

The things that the class is responsible for knowing and the actions that the class is responsible for doing

20
Q

What two questions should you ask to determine a class’s responsibilities?

A

In the context of this problem, what must the class know? What must the class do?

21
Q

Will all of a class’s actions always be directly mentioned in the problem domain description?

A

No, not always

22
Q

The                programming practice is centered on creating functions that are separate from the data that they work on.

A

procedural

23
Q

The                programming practice is centered on creating objects.

A

object-oriented

24
Q

A(n)                is a component of a class that references data.

A

data attribute

25
Q

An object is a(n)               .

A

instance

26
Q

By doing this, you can hide a class’s attribute from code outside the class.

A

begin the attribute’s name with two underscores

27
Q

A(n)                method gets the value of a data attribute but does not change it.

A

accessor

28
Q

A(n)                method stores a value in a data attribute or changes its value in some other way.

A

mutator

29
Q

The                method is automatically called when an object is created.

A

__init__

30
Q

If a class has a method named _ str _, which of these is a way to call the method?

A

by passing an instance of the class to the built in str function

class MyClass:
def __str__(self):
return “This is my custom string representation”

obj = MyClass()
string_representation = str(obj)
print(string_representation)

Output:

This is my custom string representation

31
Q

A set of standard diagrams for graphically depicting object-oriented systems is provided by               .

A

the Unified Modeling Language

32
Q

In one approach to identifying the classes in a problem, the programmer identifies the                in a description of the problem domain.

A

nouns

33
Q

In one approach to identifying a class’s data attributes and methods, the programmer identifies the class’s               .

A

responsibilities