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)

Inheritance - abstract methods & attribute.

(1) ShareShare
ReportReport
Posted on by

Hello.

I want to enforce programmers, who use a specific class, to override specific methods.

For that - I declare the main object as abstract object, and the some of methods as abstract.

But, what if those methods has [datamemberAttribute] - When I add new inherited function, the [datamemberattribute] is not copied - How can I make that [datamemberAttribute] (and any member farther) will be copied either.

Thanks :)

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Ivan (Vanya) Kashperuk Profile Picture
    on at

    I don't think that is possible in X++ at the moment.

    On a side note - why don't you uses an interface instead of an abstract class?

  • Suggested answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    First of all, what's the problem you're solving? I tried it with a custom service and it works fine; AX obviously look at parent classes for attributes. If you're reading attribute by yourself, you'll have to deal with base classes by yourself too.

    Nevertheless you can also design your class is such a way that the data member doesn't get overridden. In the example below, the data member is final and it delegates the work to a protected abstract method which will be implemented in a subclass.

    class BaseClass
    {
        [DataMemberAttribute]
        public final str parmItem(str _item = item)
        {
            if (prmIsDefault(_item))
            {
                return parmItemCore();
            }
            else
            {
                return parmItemCode(_item);
            }
        }
    
        protected abstract str parmItemCore(str _item = item)
        {
        }
    }
  • Community Member Profile Picture
    on at

    I want to make a general class:

    abstract Class MyClass extends SysAttribute

    and a method :

    [DatamemberAttribute('MyMethod')]
    
    abstract str parmMyMethod(str _value)
    
    {
    
      // .... do something
    
    }


    When I inherit MyClass,  and right click on class + "New" + "method" is see parmMyMethod method.

    Choosing it will not add also [DataMemberAttribute] clause.

    How can I also add by the above way (right click on class + "New" + "method" is see parmMyMethod method) and the [DataMemberAttribute] will be copied also.

    Thanks :)

  • Suggested answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    That's the correct and expected behavior. If you want some other behavior, write a code generator. Nevertheless I would recommend following my previous reply:

    • Review whether you need to specify the attribute in both methods (in the base and the child class) at all. Custom services doesn't require that (and I believe, but I didn't explicitly test, that neither SSRS). Unless you explain why you need, I suspect you're wasting time with a wrong problem.
    • You can avoid the whole problem by overriding a normal method and keeping data members untouched, as shown in the example above.

  • Suggested answer
    Deepak Agarwal Profile Picture
    8,602 on at

    Maybe this will help

    theaxapta.blogspot.in/.../abstract-class-and-abstract-method-in.html

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans