Help coderanch get a
new server
by contributing to the fundraiser
  • 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 and interfaces

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interface I {}
class C implements I {}
Is this true or false, C is-a I.
How do you know?
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi:
Yes it is true. IS-A concept is based on inheritance. In your example, class C implements interface I; C implements all the functions required by I. Then C is-a I. In general, a class is said to be a type of anything further up in its inheritance tree.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, here is what I can think about "why" of Marlene's question..
I considered the following example in mind,

1. Door example
interface Door {
}
class WoodenDoor implements Door {
}
class MetalDoor implements Door {
}
2. SuperStore example
interface SuperStore {
}
class KMart implements SuperStore {
}
class WalMart implements SuperStore {
}
These examples indicates that "implementing class makes concrete represenation of abstractly known entity". Thats why those classes are having IS-A relationship with those interfaces.
Now, other way of looking at things would be applying "method of elimination". There are two relations usually happen to be seen,
1. IS - A
2. HAS - A
Now, is the relation we are having is "HAS - A"? NO. Because WoodenDoor doesn't "have" Door. It "is a" door. Same for KMart and WalMart. So it has to be "IS - A" relation.
Example for "HAS - A" would be,
class Car {
Wheel[] wheels;
Machine machine;
Body body;
}

Here Car "contains" or "composed of" wheels, machine and body so it is "having" them and so the relation between car and wheels is "HAS - A".
Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I tried to answer "how you know" asked by Marlene not "why"
Regards
Maulin
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic