| Author |
IS-A / HAS-A relationships. Chapter 2 Question 14 page 180
|
Glen Iris
Ranch Hand
Joined: Jul 13, 2011
Posts: 69
|
|
You're designing a new online board game in which Floozels are a type of Jammers, Jammers can have Quizels, Quizels are a type of Klakker, and Floozels can have severl Floozets. Which of the following fragments represent this design? (choose all that apply)
The correct answers are given as A and C.
A.
C.
Given that Floozels can have several Floozets, this implies that Floozet is an instance variable. A shows it as an interface and C shows it as an instance variable.
Looking forward to your help as always :-)
|
OCPJP 6
|
 |
Joseph Arnold
Ranch Hand
Joined: Oct 05, 2010
Posts: 42
|
|
|
Floozel can have several Floozets mean there can be several instances of Floozets in floozel. Well, both options illustrate the same. Whether Floozet is a class type or an interface type does not matter. We must only ensure that there is some appropriate collection of floozets in a floozel.
|
 |
Helen Ma
Ranch Hand
Joined: Nov 01, 2011
Posts: 319
|
|
According to Effective Java by Josh Bloch, we should use interface to define object type. This is the only usage of interface. Therefore, while a class is to define type, an interface is also used for defining type.
In K&B book, use interface as if a 100% abstract class. 100% abstract class is the abstract class that only contains abstract methods. Interface contains all abstract method, too.
So, while we use class/abstract class to define type, we can also use interface to define type.
Correct me if I am wrong.
|
 |
 |
|
|
subject: IS-A / HAS-A relationships. Chapter 2 Question 14 page 180
|
|
|