Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / BP Warning question ??...
Finance forum
Answered

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

Posted on by 90
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.
 
 
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,862 Super User on at
    BP Warning question ?? "Can't define protected method in an Extension Class (final)
    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.
  • Dick de Jong Profile Picture
    Dick de Jong 90 on at
    BP Warning question ?? "Can't define protected method in an Extension Class (final)
    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
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 4,787 Super User on at
    BP Warning question ?? "Can't define protected method in an Extension Class (final)
    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
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 225,862 Super User on at
    BP Warning question ?? "Can't define protected method in an Extension Class (final)
    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.)

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,862 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans