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 :
Microsoft Dynamics AX (Archived)
Answered

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

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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.

  • Rohin Profile Picture
    4,624 on at

    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.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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
    4,624 on at

    yes , same in your terms . Can you provide please

    Thanks

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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
    4,624 on at

    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 .

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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
    4,624 on at

    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.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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
    4,624 on at

    No worries! I shall close the thread.

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

    Thanks

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans