web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Abstract, Interface and inheritance

(0) ShareShare
ReportReport
Posted on by 1,552
Hi,
 
How to decide if my base class should be abstract OR interface OR normal class that sub classes can extend?
 
Can you please give me an example and clearly explain why each one was chosen in this example
  • Suggested answer
    Anton Venter Profile Picture
    21,234 Super User 2026 Season 2 on at
    Hi,
     
    In a nutshell: in most cases you will just use classes for making business logic and or extending existing code. Abstract classes are used if you don't want the class to be instantiated directly. This is mostly used in the base/parent class which contains the 'common' code./methods. The child classes inheriting from the base/parent class specialise the common code/methods declared in the base class, therefore is does not make sense to instantiate the base class but one of the chile classes. Have a look at the Bank class and child classes.
     
    Interface classes are not used that much and forces child classes to implement methods in the child class so that the caller knows it can call those methods. Have a look at RunbaseBatch/Runbase as an example, it inherits and implements.
     
    For information about the subject, search for Object Oriented Programming (OOP).
  • Suggested answer
    GirishS Profile Picture
    27,843 Moderator on at
    Hi Junior,
     
    For interface let us consider you have two calculations - Based on some conditions you need to call the respective methods.
    For this we will create 1 method in interface.
    interface Class1
    {
         void calculations1(){}
    }
     
    Public class2
    {
         //add 1st calculations.
          void calculation1()
          {
          }
    }
     
    Public class3
    {
          //add 2nd calculations.
          void calculation1()
          {
          }
    }
    //Now we will call the respective class based on some condition.
    Public class4
    {
         If(1stCalculation)
         {
               Class1 obj = new Class2(); this will execute the logic on class2.
             
         }
         
         If(2ndCalculation)
         {
               Class1 obj = new Class3(); this will execute the logic on class3.
             
         }
     
    }
    So, in interface with the help of the single method we are calling the respective class logics which implements interface.
    Abstract class is also same as that of interface but it will have both abstract and Non abstract method. In abstract method there is no body but in Non abstract method you can add your while body. In that child class you can just simply override the logic of Non abstract method.
     
    Thanks,
    Girish S.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 475 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 399 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 374

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans