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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

BP Warning question ?? "Can't define protected method in an Extension Class (final)

(1) ShareShare
ReportReport
Posted on by 9
I will try to illustrate with a picture :
 
* ID365 has the standard Class "InventUpdate".
* InventUpdate has sub classes, such as InventUpd_Physical
* I have created extension class for BOTH InventUpdate and InventUpd_Physical 
* In the extension class InventUpdate_ClsExtension class I have added a protected method which I want to re-use in sub classes of InventUpdate, such as InventUpd_Physical.
 
To me this sounds a valid concept. My understanding of extension classes is that they decorate the class they extend. And in fact become 'one' with that class. Is I then possible to extend also a subclass (normal OO) and on that sub classed class also build an extension class?  I feel there is NOTHING wrong in this.
 
But should then the 2nd extension class be able to access protected methods of the first extension class? There are 2 options:
 
=> if the BP warning is correct and it did consider this situation, then this is NOT allowed
=> if Microsoft did not consider this situation (subclassing and extending both super and sub class), then it could be a situation that Msoft did not think about yet.
 
I would like to have code which is BP warning free. Either I must not use protected methods in extension classes, OR microsoft must remove that BP Warning.
 
Can anyone comment on this? Does anyone know why protected methods are not allowed here? Does anyone know what I should do here?
 
Looking forward to the response.
 
 
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,805 Most Valuable Professional on at
    The problem is that there is no inheritance of extension classes, therefore you can't define a method in one extension class and override it in another extension class (and get it called polymorphically). Creating an extension isn't the same thing as adding members to the original class. Extension classes are separate classes and it just look like if their methods were in augmented classes.
     
    (Moved from D365 general forum.)
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi,
     
    Because extension classes are "final" (can't be inherited), methods can’t be marked as protected.
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Dick de Jong Profile Picture
    9 on at
    Hi Martin,
     
    Thanks for your reply.
     
    I very well get your point.... I see it as follows: the extension classes are decoration classes and not polymorphistic sub classes .. 
     
    BUT: 
     
    To me it sounds valid to have an option to model generic add-on logic in an EXTENSION class that uses context from the EXTENDED class (class variables/members, context).
     
    Ideally, if that logic DOES NOT need context from the extended class we should use delegation (put that new method in totally another class).
     
    But we do have re-usable logic that is exclusively bound to the extended class and also uses context of that class. 
     
    If that is not in line with the concept of micrsofts intention of how extensions are to be used, then we should not do this. But I just want to raise the point: is it not to much shortcut to make it forbidden?
     
    I am ok with any decision / standpoint from microsoft side. ;) I just felt that I raised a valid point.
     
    You get my point?
     
    @Layan, your argument that class is final is not the answer to my question. my point is : is my scenario considered in microsoft or not when designing this architecture.
     
    Dick
  • Verified answer
    Martin Dráb Profile Picture
    237,805 Most Valuable Professional on at
    Regarding "to have an option to model generic add-on logic in an EXTENSION class that uses context from the EXTENDED class (class
    variables/members, context)",
    that's already how it works. But your requirement is different. You'd like another extension class inheriting from this extension class and override methods. I agree that it would be useful but it's not how it's done.
     
    You can log a feature request on Ideas, but I wouldn't expect any change. It would be a significant engineering challenge that Microsoft decided not to invest into and I doubt they'll change that decision without strong business reasons.

    Of course, there are other ways how to implement the logic you need. For example, you can call your own class hierarchy instead of depending on the (impossible) inheritance of extensions.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans