Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Real Time Example for "Final" keyword used in X++ Class

(0) ShareShare
ReportReport
Posted on by 4,624

Hello All,

I know Final keyword is used where we don't want to inherit that class by other class.

But I want to know why we need this or any real time example to doing so ? 

Please give me any example 

Thanks

Regards

Visvash Walia

*This post is locked for comments

  • Rohin Profile Picture
    Rohin 4,624 on at
    RE: Real Time Example for "Final" keyword used in X++ Class

    No worries! I shall close the thread.

    understanding examples is very useful for me for doing any development.

    Thanks

  • Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: Real Time Example for "Final" keyword used in X++ Class

    No problem. I mention time wasting only in the context of finding more final classes in the standard application, because you can easily do it by yourself.

    You see that just asking for examples isn't necessarily very useful, if what you really need is explanation.

    By the way, if your question has been answered, please don't forget to close the thread by marking the verified answer(s).

  • Rohin Profile Picture
    Rohin 4,624 on at
    RE: Real Time Example for "Final" keyword used in X++ Class

    Thanks for explanation on it. And also thanks for directing me in another side ("you can consult books written for other languages as well (such as Thinking in Java).").

    Indeed, I never want that you would waste your time.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: Real Time Example for "Final" keyword used in X++ Class

    I can easily find hundred examples, but you can do it by yourself, so I won't waste my time with it. But will hundred examples help you more than the single example I already gave you? I doubt so - I think what you need is understanding why developers want allowing other people to inherit from a class, or when they want to prevent it.

    In some cases, you want other people to create specialization of your class, such as when you can create custom classes inherited from RunBase. In other cases, you want to prevent it. I already mentioned one such situation - if extending a class makes no sense, any such any attempt would be a bug. If the class is final, anybody making such a mistake will get an error at compile time, making clear that it's not a valid scenario. Or you may want to be sure that nobody meddles with the critical piece of logic that your class performs, you don't have to design the class to be meaningfully extensible (e.g. which methods will be protected and which ones private), there are performance benefits of final classes and so on.

    Note this topic isn't specific to Dynamics AX; it's about object-oriented development in general, so you can consult books written for other languages as well (such as Thinking in Java).

  • Rohin Profile Picture
    Rohin 4,624 on at
    RE: Real Time Example for "Final" keyword used in X++ Class

    I want why we need to restrict the class to get extended . Any real life example( in your terms) that shows need of final keyword.  Just like we have many real life example of using Abstract or interface .

  • Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: Real Time Example for "Final" keyword used in X++ Class

    I've already done it, in my opinion.

    You really should explain what exactly you expect from us, if giving you a concrete example and explaining the reasoning behind making the class final isn't what you wanted.

  • Rohin Profile Picture
    Rohin 4,624 on at
    RE: Real Time Example for "Final" keyword used in X++ Class

    yes , same in your terms . Can you provide please

    Thanks

  • Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: Real Time Example for "Final" keyword used in X++ Class

    Then please explain what you mean by "real time example". I'm not even familiar with the term, so I thought you wanted a real life example.

  • Rohin Profile Picture
    Rohin 4,624 on at
    RE: Real Time Example for "Finial" keyword used in X++ Class

    Ohh! i apologize its final .

     Yes , SysObsoleteAttribute Class is final in AX2012R2 also.

    But still ,  i am not getting my proper answer. If you have any real time example , please share.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: Real Time Example for "Finial" keyword used in X++ Class

    You have access to source code of the whole application, therefore you can easily find many examples there.

    For instance, SysObsoleteAttribute class is final (at least in AX 7), because there is no reasonable case when anybody should inherit from it.

    By the way, it's final, not finial.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,820 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans