Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IS-A / HAS-A relationships. Chapter 2 Question 14 page 180

 
Glen Iris
Ranch Hand
Posts: 172
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :-)
 
Joseph Arnold
Ranch Hand
Posts: 42
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alexander Shrago
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt about correct answers to Chapter 2 Question 14

What is Jammers, Quizels and so on? They are not strict names оf classes and interfaces but samples of real objects

So answer "D" is also correct inspite of authors opinion:

import java.util.*;
interface Jammer extends Quizel { }
interface Klakker { }
interface Quizel extends Klakker { }
interface Floozel extends Jammer, Floozet { }
interface Floozet { }

Checking it:
floozels are a type of Jammers - yes
quizels are a type of Klakker - yes
Jammers can have Quizels and Floozels can have several Floozets - Where do you see that they can not ??

Am I wrong?

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to understand IS-A and HAS-A relationships...
 
Alexander Shrago
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chapter 2 Question 14 is

"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 several Floozets. Which of the
following fragments represent this design?"

I get that you mean, but
where are no words "IS-A" or "HAS-A"

"HAS-A" relationships can appear later during realization

Where am I wrong?


 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alexander Shrago wrote:Chapter 2 Question 14 is

"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 several Floozets. Which of the
following fragments represent this design?"

I get that you mean, but
where are no words "IS-A" or "HAS-A"

"HAS-A" relationships can appear later during realization

Where am I wrong?




 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alexander Shrago wrote:

So answer "D" is also correct inspite of authors opinion:

import java.util.*;
interface Jammer extends Quizel { }
interface Klakker { }
interface Quizel extends Klakker { }
interface Floozel extends Jammer, Floozet { }
interface Floozet { }

Checking it:
floozels are a type of Jammers - yes
quizels are a type of Klakker - yes
Jammers can have Quizels and Floozels can have several Floozets - Where do you see that they can not ??

spot on! you got it there...
Alexander Shrago wrote:
Am I wrong?

yes...
 
Guilherme Bazilio
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Java does not support multiple inheritance! So answer D is false!

 
Ted North
Ranch Hand
Posts: 201
1
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glen Iris wrote: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 :-)


I made a UML diagram that may explain things:


With interfaces or classes the same IS-A/HAS-A relationships apply. If a class implements an interface then that class IS-A whatever that interface is. This is what is so handy-dandy about polymorphism. Plus a class can implement multiple interfaces while it can only extend one class. Interfaces normally are outside of the class hierarchy too and enable some sort of action.

For instance Dog extends Animal and Dog and and animal both implement the interface Eat. A java programmer can reuse the Eat interface for a class that pertains to Androids, Animals, or Humans.

I hope this made some sense to you. Keep reading about it and coding, you will understand in time Glen Iris.

 
Alexander Shrago
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guilherme Bazilio wrote:

Java does not support multiple inheritance! So answer D is false!



There are no problem for an interface to extend many interfaces. Check it!

-------------------
Sorry for all !!

I read the question inattentive - it is correctly formulated:
"Which of the following fragments represent this design?..."

The question is about the design representation, not about possibilities to have - so I am wrong about "D" ))

 
Guilherme Bazilio
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alexander Shrago wrote:
Guilherme Bazilio wrote:

Java does not support multiple inheritance! So answer D is false!



There are no problem for an interface to extend many interfaces. Check it!



You're totally right!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic