Chapter 7 Object-Oriented Design Flashcards
Name the four basic activities that are involved in a software development process.
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).
Who creates/specifies software requirements, the client or the developer? Discuss.
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.
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)
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 can identifying the nouns in a problem specification help you design an object-oriented solution to the problem?
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.
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.
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.
What is the difference between a static variable and an instance variable?
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.
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.
Assuming you decide to use the identifier totalBalance, the declaration is: private static int totalBalance = 0;
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.
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;
What kinds of variables can the main method of any program reference? Why
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.
Describe a dependency relationship between two classes.
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.
Explain how a class can have an association with itself.
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.
What is an aggregate object?
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.
What does the this reference refer to?
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.
What is the difference between a class and an interface?
A class can be instantiated; an interface cannot. An interface contains a set of abstract methods for which a class provides the implementation.
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.
public interface Nameable { public void setName(String name); public String getName(); }