• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :-)
 
Ranch Hand
Posts: 42
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?


 
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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

 
Ranch Hand
Posts: 201
1
Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic