0

I came across this question and it states

When it comes to "dynamic polymorphism" "IS-A" relation holds, what does IS-A relation holds mean here ?

What other types of relations are there ? Any references that might explain them ?

Community
  • 1
  • 1
Rajeshwar
  • 11,179
  • 26
  • 86
  • 158
  • And your first thought ask a way too broad question here instead of trying Google? – John3136 Sep 15 '14 at 04:53
  • 1
    "other types of relations": "has-a" and "is-implemented-in-terms-of", the former means "combination", the latter equals with "private inheritance". The question is too broad, google it. – Anthony Cooper Sep 15 '14 at 04:59

4 Answers4

3

There is is-a and has-a and they mean exactly what you'd expect them to mean.

Has-a means a type that contains another type within it. Is-a means a type that is derived from another type.

Returning to the simple examples we first examined when we started looking into object oriented concepts, a car is-a vehicle but it has-a steering wheel.

Or, as an alternative consider the following class hierarchy:

shape:
    coordinate c

square: shape
    size s

Here, a square inherits everything from a shape so it is-a shape. However, the size of the square is not part of the hierarchy, so a square has-a size.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
2

Inheritance (IS-A) think overriding, expanding/hiding base-class functionality.

Aggregation (HAS-A) think holding a pointer to object and not controlling it's lifetime.

Composition (Stronger HAS-A) think holding a stack-allocated object, RAII etc.

Good introductory reading can be found on Wikipedia:

pdeschain
  • 1,411
  • 12
  • 21
1

IS-A is used to describe the relationship between the derived object and the base object. The derived object is often a specialised version of the base object, and so you can say the derived object is a base object

See this simple example, a circle specialising a shape base class.

struct shape
{
    virtual int area() = 0;
};

struct circle : shape // circle is a shape
{

};
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
1

what does IS-A relation holds mean here ?

It means that all objects that are derived from some base type are in fact objects of that base type, even if they are referred to in your program by their actual types.

Take this (Java) example:

class Animal {    
   public void move(){
      System.out.println("Animals can move");
   }
}

class Dog extends Animal {

   public void move() {
      System.out.println("Dogs can walk and run");
   }
}

If you were to take the following test:

public class TestDog {

   public static void main(String args[]) {
      Animal a = new Animal(); // Animal reference and object
      Animal b = new Dog(); // Animal reference but Dog object

      a.move();//output: Animals can move

      b.move();//output:Dogs can walk and run
   }
}

You would see that the two objects in this program are Animals, even though one of them is actually a Dog. An Animal object reference can be used to refer to any object that derives from Animal, hence the is a relationship. A Dog is an Animal.

See this post for this example reference

What other types of relations are there ?

Most people refer to the is-a relationship alongside has-a, which means that an object may have specific properties or attributes, but isn't necessarily defined by those characteristics. For example, a Dog has-a name, a weight, four legs, etc., but that's not necessarily what makes it a dog.

Community
  • 1
  • 1
Ryan J
  • 8,275
  • 3
  • 25
  • 28