You must Sign In to post a response.
  • Category: .NET

    When do we go for Abstraction and when do we go for the inteface

    when do we go for Abstraction and when do we go for the interface
    can any one give real time project example

    as we have Override feature in c#.Net , Why do we go for the Abstraction
    can any one explain the examples
  • #762359
    Hi Praveen,

    Abstraction :

    When you want to get parent details in child class, in that case we go for Abstraction,


    If you want to know department wise employee details then we go for Abstract class.

    Here, Dept is parent class and Employee is child class.

    Interfaces :

    If you want to inherits more than one parent info into child class in that scenario we go for Interfaces,


    Employee Payslip generation, time we require Leave Management and Salary Details and PF details etc..

    For each and everything we are maintain separately, but while generate payslip we require all the details at a time, in that scenario Interfaces will help you to fetch all the class info.

    Hope this will help you, if you want to know more about this just Google it and R&D about this.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #762360

    Interfaces are used to achieve multiple inheritance in c# programming.

    public abstract class myabstract: IA, IB //IA and IB are two interfaces, here we achieving multiple inheritance
    public abstract viod m1(); //abstract method
    public void m2() //non abstract method
    //some logic

    Interface Rules:
    1.Interface contain only abstract methods, which are public abstract by default.
    2.Interface can implement another interface but cannot implement abstract class.
    3.Object cannot be created for interface, reference can be created.

    public interface ISample:IMysample
    void mymethod();
    void mymethod2();


    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

  • #762367

    If you want a method to be overridden in all the child classes what you will do?
    Here abstract comes in to picture.

    Just declare that method as abstract method, by declaring abstract method in parent class you are forcing all the child classes to override the abstract method.

    If you have at least one abstract method then that class should be declared as abstract class.

    Rules of abstract class:
    1.We cannot create object of abstract class.
    2.Abstract class can contain both abstract and non abstract methods.


    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

  • Sign In to post your comments