Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A
dotnetinter

What is the difference between IS A and Can a Relationship?( .NET Interview questions with answers)

This question is taken from the .NET interview questions and answers book written by ShivprasadKoirala.


Take a look at following code samples.
Sample 1
classCustomer
   {
publicvoidMakeOrder()
       {
       }
voidCancelOrder()
       {
       }
   }
classGoldCustomer : Customer
   {
publicvoidGetDiscountOnOrder()
       {
       }
publicvoidReplaceOrder()
       {
       }
   }

Sample 2
interfaceIPerson
{
void Walk();
void Sit();
}

classCustomer : IPerson
{
publicvoid Walk()
   {
   }

publicvoid Sit()
   {
   }
}
classSupplier : IPerson
{
publicvoid Walk()
   {
   }

publicvoid Sit()
   {
   }
}

In First sample, Whatever Customer can doGold Customer can also do.  Gold customer has all the capability Customer had. These happened because one is derived from other. We say “Gold Customer is also a Customer”. And hence it is referred as “Is A” relationship.


Now let’s come to second example.
Interface IPerson declares what all things need to be there in them who implement is. Customer can walk and sit, also Supplier can walk and sit. It is possible because both of them implement IPerson interface. We say “Customer can do what was there in IPerson” and “Supplier can do what was there in the IPerson” And hence we call it as “Can a” relationship.

Below is a simple .NET interview question video with answer which explains Association , aggregation and composition.

Tags: aggregation, composition interview questions, csharp interview questions, has a and is a relationship, information technology questions, oop interview questions, programming interview questions
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments