Deck 5: Interfaces, Implementations, and Polymorphism

ملء الشاشة (f)
exit full mode
سؤال
You can use a for loop on any collection.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Once the designer of a collection class has obtained its interface, the implementation of the class includes completing code for the methods.
سؤال
When Python sees the in operator used with a collection, it runs the __contains__ method in the collection's class.
سؤال
When used with a bag object, the in operator returns an integer value.
سؤال
Software bags can grow as more items are added, or they can shrink as items are removed.
سؤال
The logical size of an array-based bag will always be the same as the array's capacity.
سؤال
A precondition is a statement of what must be true for a method to perform its actions correctly.
سؤال
When the LinkedBag structure is not empty, self.items refers to the last node in the linked structure.
سؤال
Whenever you need to use the logical size of the bag within a class definition, run len(self) instead of referring directly to the instance variable self.size .
سؤال
Each time you run Python's document function to obtain information about a module, data type, method, or function, you are accessing documentation about that resource's interface.
سؤال
The clear method empties a bag.
سؤال
The statement in the ArrayBag constructor to copy an item from a source collection to a new ArrayBag object is self.init(item) .
سؤال
A bag is a type of ordered collection.
سؤال
When defining the Bag class, the __init__ operation is the constructor for the class.
سؤال
An interface's documentation gives you enough information to know how to use or call a method and what to expect it to accomplish and return.
سؤال
Data that is needed to represent the state of a collection are assigned instance variables in the __help__ method of the class.
سؤال
You should always try to hide the implementing data structures behind a wall of method calls on the object being implemented.
سؤال
A docstring is a string enclosed in double quotes that will be displayed when Python's help function is run on a resource.
سؤال
When Python sees a for loop on an iterable object, it runs that object's __add__ method.
سؤال
The __iter__ method uses a yield statement to send each item to the calling for loop.
سؤال
Which of the following is one of the hallmarks of well-designed software?

A) a random grouping of interfaces to ensure secure code
B) an interface that is tightly coupled to the implementation
C) the clean separation of interfaces from implementations
D) a sophisticated interface with a high learning curve
سؤال
In the Bag class defined in the chapter, what is one of the purposes of the sourceCollection argument in the __init__ method?

A) to create a bag with the contents of another collection
B) to delete the contents of an existing collection
C) to define source code for the method
D) to add data to an existing bag collection
سؤال
In the ArrayBag class, why must the ArrayBag object track its logical size in a separate instance variable?

A) because the physical size is always smaller than the logical size
B) because the initial size of the object can't be changed
C) because the logical size will likely differ from the array's capacity
D) because the array size and the logical size are identical
سؤال
The running times of the operations of ArrayBag and LinkedBag are similar.
سؤال
In the remove method for LinkedBag, if probe points to the node at the head of the linked structure, trailer will point to the tail.
سؤال
What word is best defined as the use of common names for operations on different types of collections?

A) anachronism
B) polymorphism
C) concatenation
D) modularization
سؤال
The design and implementation of a collection class consists of two steps. What is the first step?

A) document the class using docstrings
B) choose an appropriate data structure
C) write the code for the defined methods
D) test the method using sample data
سؤال
What is the name of the method that performs the constructor operation for a class?

A) __eq__
B) __iter__
C) __add__
D) __init__
سؤال
The code for the add method for the ArrayBag class is shown below. What is the missing code?
Def add(self, item):
Self.items[len(self)] = item
< missing code >

A) self.items +=1
B) self = self + 1
C) self.size += 1
D) self.len = self.items
سؤال
In the ArrayBag class, what must the __init__ method do if a source collection is specified?

A) the new instantiation of the bag must be copied to the source collection.
B) the source collection must be initialized with the clear method
C) the data in the source collection must be deleted
D) the data in the source collection must be copied
سؤال
What does Python do when it sees a for loop on an iterable object?

A) executes a do loop
B) runs the __iter__ method
C) runs the clear method
D) executes a return statement
سؤال
Which Python function allows you to obtain information about a module, data type, method, or function?

A) help
B) list
C) doc
D) info
سؤال
The __iter__ method is identical in the ArrayBag and LinkedBag classes.
سؤال
Which of the following is NOT a goal of the barrier that separates an interface from implementation?

A) allows users to quickly glue resources together
B) allows alternative implementations of the same resource
C) changes to a resource's implementations do not disturb user code
D) increases the learning curve for resource's users
سؤال
Class diagrams show the relationships among classes at various levels of detail.
سؤال
Which is true about a bag collection?

A) it is an unordered collection
B) it is a standard collection type in Python
C) bags can contain only numeric objects
D) bags are of a fixed size
سؤال
What is found in the body of the method code that is used to document the method?

A) mutators
B) parameters
C) docstring
D) arguments
سؤال
While desirable, testing is not a critical part of software resource development.
سؤال
The code for the __iter__ method is shown below. What is the missing code?
Def __iter__(self):
< missing code >
While cursor < len(self):
Yield self.items[cursor]
Cursor += 1

A) cursor = 0
B) cursor = 1
C) cursor = self.size
D) cursor = len(self)
سؤال
What is it called when the contents of two bags are combined into a third bag?

A) iteration
B) appending
C) concatenation
D) reduction
سؤال
Why won't some of the ArrayBag methods require changes when implementing the LinkedBag class?

A) because the methods don't use the self variable
B) because the ArrayBag class is based on lists
C) because the LinkedBag object is not iterable
D) because the methods don't directly access the array variable
سؤال
Which of the following methods will require changes between the ArrayBag and the LinkedBag class?

A) isEmpty
B) remove
C) __eq__
D) __len__
سؤال
What testing tool can be used to help ensure that a resource meets its requirements?

A) unittest
B) pytest
C) pyunit
D) unitcheck
سؤال
The following code copies the data from a specified source collection in the LinkedBag __init__ method. What is the missing code? for item in sourceCollection:
< missing code >

A) add(item.self)
B) self.add(item)
C) self.item(add)
D) self.item = source.item
سؤال
What is the last step in the remove function in the ArrayBag class?

A) check the precondition
B) shift items to the right
C) resize the array
D) search for the target item index
سؤال
What method does Python run when it sees the in operator used with a collection?

A) __contains__
B) __iter__
C) __eq__
D) __add__
سؤال
In the ArrayBag class, what function does the __str__ method use to generate a sequence of strings from a bag?

A) count
B) len
C) add
D) map
سؤال
What is one of the pieces of data that must be initialized in the __init__ method in the LinkedBag class?

A) an array
B) a linked structure
C) a physical size
D) a string pointer
سؤال
How can the performance of the in and remove functions be described in the two bag implementations?

A) they take linear time
B) they take constant time
C) the performance is exponential according to the size of the bag
D) the performance is logarithmic according to the size of the bag
سؤال
Which of the following is a visual aid to help catalog resources in your software toolbox?

A) docstring
B) method mapper
C) unit modeler
D) class diagram
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 5: Interfaces, Implementations, and Polymorphism
1
You can use a for loop on any collection.
True
2
Once the designer of a collection class has obtained its interface, the implementation of the class includes completing code for the methods.
True
3
When Python sees the in operator used with a collection, it runs the __contains__ method in the collection's class.
True
4
When used with a bag object, the in operator returns an integer value.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
5
Software bags can grow as more items are added, or they can shrink as items are removed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
6
The logical size of an array-based bag will always be the same as the array's capacity.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
7
A precondition is a statement of what must be true for a method to perform its actions correctly.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
8
When the LinkedBag structure is not empty, self.items refers to the last node in the linked structure.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
9
Whenever you need to use the logical size of the bag within a class definition, run len(self) instead of referring directly to the instance variable self.size .
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
10
Each time you run Python's document function to obtain information about a module, data type, method, or function, you are accessing documentation about that resource's interface.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
11
The clear method empties a bag.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
12
The statement in the ArrayBag constructor to copy an item from a source collection to a new ArrayBag object is self.init(item) .
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
13
A bag is a type of ordered collection.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
14
When defining the Bag class, the __init__ operation is the constructor for the class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
15
An interface's documentation gives you enough information to know how to use or call a method and what to expect it to accomplish and return.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
16
Data that is needed to represent the state of a collection are assigned instance variables in the __help__ method of the class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
17
You should always try to hide the implementing data structures behind a wall of method calls on the object being implemented.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
18
A docstring is a string enclosed in double quotes that will be displayed when Python's help function is run on a resource.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
19
When Python sees a for loop on an iterable object, it runs that object's __add__ method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
20
The __iter__ method uses a yield statement to send each item to the calling for loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which of the following is one of the hallmarks of well-designed software?

A) a random grouping of interfaces to ensure secure code
B) an interface that is tightly coupled to the implementation
C) the clean separation of interfaces from implementations
D) a sophisticated interface with a high learning curve
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
22
In the Bag class defined in the chapter, what is one of the purposes of the sourceCollection argument in the __init__ method?

A) to create a bag with the contents of another collection
B) to delete the contents of an existing collection
C) to define source code for the method
D) to add data to an existing bag collection
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
23
In the ArrayBag class, why must the ArrayBag object track its logical size in a separate instance variable?

A) because the physical size is always smaller than the logical size
B) because the initial size of the object can't be changed
C) because the logical size will likely differ from the array's capacity
D) because the array size and the logical size are identical
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
24
The running times of the operations of ArrayBag and LinkedBag are similar.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
25
In the remove method for LinkedBag, if probe points to the node at the head of the linked structure, trailer will point to the tail.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
26
What word is best defined as the use of common names for operations on different types of collections?

A) anachronism
B) polymorphism
C) concatenation
D) modularization
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
27
The design and implementation of a collection class consists of two steps. What is the first step?

A) document the class using docstrings
B) choose an appropriate data structure
C) write the code for the defined methods
D) test the method using sample data
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
28
What is the name of the method that performs the constructor operation for a class?

A) __eq__
B) __iter__
C) __add__
D) __init__
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
29
The code for the add method for the ArrayBag class is shown below. What is the missing code?
Def add(self, item):
Self.items[len(self)] = item
< missing code >

A) self.items +=1
B) self = self + 1
C) self.size += 1
D) self.len = self.items
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
30
In the ArrayBag class, what must the __init__ method do if a source collection is specified?

A) the new instantiation of the bag must be copied to the source collection.
B) the source collection must be initialized with the clear method
C) the data in the source collection must be deleted
D) the data in the source collection must be copied
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
31
What does Python do when it sees a for loop on an iterable object?

A) executes a do loop
B) runs the __iter__ method
C) runs the clear method
D) executes a return statement
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
32
Which Python function allows you to obtain information about a module, data type, method, or function?

A) help
B) list
C) doc
D) info
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
33
The __iter__ method is identical in the ArrayBag and LinkedBag classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
34
Which of the following is NOT a goal of the barrier that separates an interface from implementation?

A) allows users to quickly glue resources together
B) allows alternative implementations of the same resource
C) changes to a resource's implementations do not disturb user code
D) increases the learning curve for resource's users
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
35
Class diagrams show the relationships among classes at various levels of detail.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
36
Which is true about a bag collection?

A) it is an unordered collection
B) it is a standard collection type in Python
C) bags can contain only numeric objects
D) bags are of a fixed size
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
37
What is found in the body of the method code that is used to document the method?

A) mutators
B) parameters
C) docstring
D) arguments
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
38
While desirable, testing is not a critical part of software resource development.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
39
The code for the __iter__ method is shown below. What is the missing code?
Def __iter__(self):
< missing code >
While cursor < len(self):
Yield self.items[cursor]
Cursor += 1

A) cursor = 0
B) cursor = 1
C) cursor = self.size
D) cursor = len(self)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
40
What is it called when the contents of two bags are combined into a third bag?

A) iteration
B) appending
C) concatenation
D) reduction
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
41
Why won't some of the ArrayBag methods require changes when implementing the LinkedBag class?

A) because the methods don't use the self variable
B) because the ArrayBag class is based on lists
C) because the LinkedBag object is not iterable
D) because the methods don't directly access the array variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
42
Which of the following methods will require changes between the ArrayBag and the LinkedBag class?

A) isEmpty
B) remove
C) __eq__
D) __len__
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
43
What testing tool can be used to help ensure that a resource meets its requirements?

A) unittest
B) pytest
C) pyunit
D) unitcheck
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
44
The following code copies the data from a specified source collection in the LinkedBag __init__ method. What is the missing code? for item in sourceCollection:
< missing code >

A) add(item.self)
B) self.add(item)
C) self.item(add)
D) self.item = source.item
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
45
What is the last step in the remove function in the ArrayBag class?

A) check the precondition
B) shift items to the right
C) resize the array
D) search for the target item index
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
46
What method does Python run when it sees the in operator used with a collection?

A) __contains__
B) __iter__
C) __eq__
D) __add__
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
47
In the ArrayBag class, what function does the __str__ method use to generate a sequence of strings from a bag?

A) count
B) len
C) add
D) map
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
48
What is one of the pieces of data that must be initialized in the __init__ method in the LinkedBag class?

A) an array
B) a linked structure
C) a physical size
D) a string pointer
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
49
How can the performance of the in and remove functions be described in the two bag implementations?

A) they take linear time
B) they take constant time
C) the performance is exponential according to the size of the bag
D) the performance is logarithmic according to the size of the bag
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
50
Which of the following is a visual aid to help catalog resources in your software toolbox?

A) docstring
B) method mapper
C) unit modeler
D) class diagram
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.