C# .NET - Abstract class and Interface - Asked By karur krishna madhu on 16-Jul-13 11:32 AM

abstract Human
{

   public abstract void eat();
   public abstract  string Qualification();
   public abstract  string Office name();



}

class Bird:Human
{


  public void eat();
  public string qualification();---Bird doesn't have qualification.
  public string Office name();---- Bird doesn't have office name.
 

}

So i will move this functionality from an abstract class to an interface

Interface Ieat

{

   public void eat();
}

When we have related methods for unrelated objects of classess then we move such functionality in an Interface.  this is very simple scenario.  My question is how to identify if a method of parent class can be a valid entry to the child class.how to identify if it has to be in an abstract class as an abstract method or to be moved to interface.  do we have "is a" and "has a" kind of relationship to identify the same
Robbe Morris replied to karur krishna madhu on 16-Jul-13 11:38 AM
This might be helpful.

https://www.nullskull.com/articles/20031103.asp

I'm not exactly sure what you are after here.  That said, it is important to note that C# does not support multiple inheritance of "classes" but it does support implementing multiple interfaces.

I "think" you might be trying to stuff too much into one "interface" of sorts then getting frustrated when one of your higher level classes doesn't need a method or property.  You "may" want to consider small interfaces and only implementing those Interfaces that are needed on a given class.  This would let you pass around the based functionality of a class as well as create methods that accept a limited Interface and still pass the same class through as a parameter.
karur krishna madhu replied to Robbe Morris on 17-Jul-13 04:31 AM
Thanks Morris!