Monday, May 21, 2012

Interface and Abstract

Well, Every one has different way of style to explain the interface and abstract  . 

here am going to explain when to use what .
straight forward explanation is , where you need to implement some function in the derived (child) class , then you need to use Interface whereas you want to use parent class implementation then you could have use Abstract .

There are some other reason of having Interface .

have a look at the below example

   class parent {
 
    void  business() =0 ;
   };


class child : public parent {

void business() {
// doing some business for survival .
}

};
 

Conclusion : Parent wants all the children to do their own business , In this case we could have use Interface



 class parent {
 
   virtual  void  business(){
     // family business
     } ;
   };


class child : public parent {

void business() {
// doing some business  .
}

};



here child  is implementing some business , But it is not necessary since parent is doing family business .

we are giving freedom to child , if you want implement it else will consider his business is family business

Conclusion : There are some situation where child may or may not implement business , If child is doing some business ,then we are taking that else taking from parent .

















No comments:

Post a Comment