Chapter 7 Object-Oriented Design Flashcards

1
Q

Name the four basic activities that are involved in a software development process.

A

The four basic activities in software development are requirements analysis (deciding what the program should do), design (deciding how to do it), implementation (writing the solution in source code), and testing (validating the implementation).

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

Who creates/specifies software requirements, the client or the developer? Discuss.

A

Typically the client provides an initial set of requirements or a description of a problem they would like to have solved. It is the responsibility of the software developer to work with the client to make sure the requirements or problem statement is correct and unambiguous.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
Compare and contrast the four basic development activities presented in this section with the five general problem-solving steps presented in
Chapter 1 (Section 1.6)
A

Software development is a problem-solving activity. Therefore, it is not surprising that the four basic development activities presented in this
section are essentially the same as the five general problem-solving steps presented in Section 1.6. “Establishing the requirements” directly corresponds to “understanding the problem.” “Designing a solution” and
“considering alternative designs” taken together correspond to “creating
a design”––in the case of software, the design is the solution. Finally, in
both approaches we include “implementation” and “testing” stages.

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

How can identifying the nouns in a problem specification help you design an object-oriented solution to the problem?

A

Identifying the nouns in a problem specification can help you identify potential classes to use when developing an object-oriented solution to
a problem. The nouns in the specification often correspond to objects that should be represented in the solution.

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

Is it important to identify and define all of the methods that a class will contain during the early stages of problem solution design? Discuss.

A
It is not crucial to identify and define all the methods that a class will contain during the early stages of problem solution design. It is often sufficient to just identify those methods that provide the primary
responsibilities of the class. Additional methods can be added to a class as needed, when you evolve and add detail to your design.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between a static variable and an instance variable?

A

Memory space for an instance variable is created for each object that is instantiated from a class. A static variable is shared among all objects of a class.

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

Assume you are defining a BankAccount class whose objects each represent a separate bank account. Write a declaration for a variable of the class that will hold the combined total balance of all the bank accounts represented by the class.

A

Assuming you decide to use the identifier totalBalance, the declaration is: private static int totalBalance = 0;

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

Assume you are defining a BankAccount class whose objects each represent a separate bank account. Write a declaration for a variable of the class that will hold the minimum balance that each account must maintain.

A

Assuming that the minimum required is 100 and you decide to use the
identifier MIN_BALANCE, the declaration is:
public static final int MIN_BALANCE = 100;

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

What kinds of variables can the main method of any program reference? Why

A

The main method of any program is static, and can refer only to static or local variables. Therefore, a main method could not refer to instance variables declared at the class level.

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

Describe a dependency relationship between two classes.

A

A dependency relationship between two classes occurs when one class relies on the functionality of the other. It is often referred to as a “uses” relationship.

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

Explain how a class can have an association with itself.

A

A method executed through an object might take as a parameter another object created from the same class. For example, the concat method of the String class is executed through one String object and takes another String object as a parameter.

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

What is an aggregate object?

A

An aggregate object is an object that has other objects as instance data.
That is, an aggregate object is one that is made up of other objects.

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

What does the this reference refer to?

A
The this reference always refers to the currently executing object. A non-static method of a class is written generically for all objects of the
class, but it is invoked through a particular object. The this reference, therefore, refers to the object through which that method is currently being executed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between a class and an interface?

A

A class can be instantiated; an interface cannot. An interface contains a set of abstract methods for which a class provides the implementation.

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

Define a Java interface called Nameable. Classes that implement this interface must provide a setName method that requires a single String parameter and returns nothing, and a getName method that has no
parameters and returns a String.

A
public interface Nameable
{
public void setName(String name);
public String getName();
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False? Explain.

a. A Java interface can include only abstract methods, nothing else.
b. An abstract method is a method that does not have an implementation.
c. All of the methods included in a Java interface definition must be abstract.
d. A class that implements an interface can define only those methods that are included in the interface.
e. Multiple classes can implement the same interface.
f. A class can implement more than one interface.
g. All classes that implement an interface must provide the exact same definitions of the methods that are included in the interface.

A

a. False – An interface can also include constants.
b. True – There is no body of code defined for an abstract method.
c. True – An interface is a collection of constants and abstract methods.
d. False – Although the class must define the methods that are included in the interface, the class can also define additional methods.
e. True – As long as each of the implementing classes provides the required methods.
f. True – As long as the class provides the required methods for each interface it implements.
g. False – Although the signatures of the methods must be the same, the implementations of the methods can be different.

17
Q

Using the enumerated type Season as defined in this section, what is the output from the following code sequence?

Season time1, time2;
time1 = Season.winter;
time2 = Season.summer;
System.out.println(time1);
System.out.println(time2.name());
System.out.println(time1.ordinal());
System.out.println(time2.getSpan());
A

Using the enumerated type Season as defined in this section, the output is

winter
summer
0
June through August

18
Q

What is method decomposition?

A

Method decomposition is the process of dividing a complex method into several support methods to get the job done. This simplifies and facilitates the design of the program.

19
Q

Answer the following questions about the PigLatinTranslator class.

a. No constructor is defined. Why not?
b. Some of the defined methods are private. Why?
c. A Scanner object is declared in the translate method. What is it used to scan?

A

Based on the PigLatinTranslator class:

a. The service provided by the class, namely to translate a string into Pig Latin, is accessed through a static method. Therefore, there is no need to create an object of the class. It follows that there is no need for a constructor.
b. The methods defined as private methods do not provide services directly to clients of the class. Instead, they are used to support the public method translate.
c. The Scanner object declared in the translate method is used to scan the string sentence, which is passed to the method by the client.

20
Q

Identify the resultant sequence of calls/returns of PigLatinTranslator support methods when translate is invoked with the following actual parameters.

a. “animal”
b. “hello”
c. “We are the champions”

A

The sequence of calls is:
a. translate – translateWord - beginsWithVowel
b. translate – translateWord - beginsWithVowel -
beginsWithBlend
c. translate – translateWord – beginsWithVowel–beginsWithBl
end – translateWord – beginsWithVowel – translateWord
– beginsWithVowel – beginsWithBlend – translateWord –beginsWithVowel - beginsWithBlend

21
Q

How are objects passed as parameters?

A

Objects are passed to methods by copying the reference to the object (its address). Therefore, the actual and formal parameters of a method become aliases of each other.

22
Q

How are overloaded methods distinguished from each other?

A

Overloaded methods are distinguished by having a unique signature, which includes the number, order, and type of the parameters. The return type is not part of the signature.

23
Q

For each of the following pairs of method headers, state whether or not the signatures are distinct. If not, explain why not.

a. String describe(String name, int count)
String describe(int count, String name)
b. void count( )
int count( )
c. int howMany(int compareValue)
int howMany(int ceiling)
d. boolean greater(int value1)
boolean greater(int value1, int value2)
A

a. They are distinct.
b. They are not distinct. The return type of a method is not part of its signature.
c. They are not distinct. The names of a method’s parameters are not part of its signature.
d. They are distinct

24
Q

The Num class is defined in Section 7.7. Overload the constructor of that class by defining a second constructor which takes no parameters and sets the value attribute to zero.

A
//------------------------------------------------------
// Sets up the new Num object, storing a default value
// of 0.
//------------------------------------------------------
public Num()
{
value = 0;
}
25
Q

Select the term from the following list that best matches each of the following phrases:

black-box, defects, regression, review, test case, test suite, walkthrough, white-box

a. Running previous test cases after a change is made to a program to help ensure that the change did not introduce an error.
b. A meeting in which several people collectively evaluate an artifact.
c. A review that steps carefully through a document, evaluating each section.
d. The goal of testing is to discover these.
e. A description of the input and corresponding expected output of a code unit being tested.
f. A set of test cases that covers various aspects of a system.
g. With this testing approach, test cases are based solely on requirement specifications.
h. With this testing approach, test cases are based on the internal workings of the program

A

The word that best matches is

a. regression b. review c. walkthrough d. defects
e. test case f. test suite g. black-box h. white-box

26
Q

What general guidelines for GUI design are presented in this section?

A

The general guidelines for GUI design include: know the needs and characteristics of the user, prevent user errors when possible, optimize user abilities by providing shortcuts and other redundant means to accomplish a task, and be consistent in GUI layout and coloring schemes.

27
Q

Why is a good user interface design so important?

A

A good user interface design is very important because to the user, the interface is the program. Since it is the only way the user interacts with the program, in the user’s mind the interface represents the entire program.

28
Q

When is a layout manager consulted?

A

A layout manager is consulted whenever the visual appearance of its components might be affected, such as when the container is resized or when a new component is added to the container.

29
Q

How does the flow layout manager behave?

A

Flow layout attempts to put as many components on a row as possible. Multiple rows are created as needed.

30
Q

Describe the areas of a border layout.

A

Border layout is divided into five areas: North, South, East, West, and Center. The North and South areas are at the top and bottom of the container, respectively, and span the entire width of the container. Sandwiched between them, from left to right, are the West, Center, and East areas. Any unused area takes up no space, and the others fill in as needed.

31
Q

What effect does a glue component in a box layout have?

A

A glue component in a box layout dictates where any extra space in the layout should go. It expands as necessary, but takes up no space if there is no extra space to distribute.

32
Q

What is the role of the BorderFactory class?

A

The BorderFactory class contains several methods used to create borders that can be applied to components.

33
Q

List and briefly describe each of the border types presented in this section.

A

The border types presented in this section include: empty—buffering space only, line—a simple line, etched—etched groove, bevel—component appears raised or sunken, titled—text title, matte—edges may have separate sizes, and compound—a combination of two borders.

34
Q

What is the containment hierarchy for a GUI?

A

The containment hierarchy for a GUI is the set of nested containers and the other components they contain. The containment hierarchy can be
described as a tree.

35
Q

Draw the containment hierarchy tree for the LeftRight application GUI presented in Chapter 5.

A

See 7.35