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)

Static method new and new method and static construct method

(0) ShareShare
ReportReport
Posted on by

Hello everyone

Can anyone explains what are differences between 

Static new method and new method and static construct method

i saw article in MS says that

https://msdn.microsoft.com/en-us/library/aa854210.aspx

  • Each class must have a single public construction method unless the class is abstract. If no initialization is required, use a static construct method. Otherwise, use a static new… method (the default constructor (new method) for the class should be protected).

  • Each class should have at least one static construct method method. Warning icon

  • Each class should have at least one static new… method.

  • Each class should have a new method (the default constructor). This method should be protected.

- point no 3 and 4 speaks about static new and new !!! can any one explain difference between static new and new
- difference between construct method and static new and why static new should be protected 

- what advantage of using construct instead of static new 

Thanks for all members

*This post is locked for comments

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

    The new "method" is a constructor, which is a special language construct for creating objects. You use it like this: new Object().

    Everything else you mentioned are just normal static methods, without any special meaning in the language. They're "factory" methods, i.e. they're also used to create objects, but they depend on constructors to do that. Names like construct() and new...() (e.g. newFromParameters()) are mere conventions.

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Maybe they meant main method for the static call, since that is the entry point for any class when it is being opened via a menu item, where you instantiate it with a constructor (that creates a new instances using the new() method), initialization, then executing the main business logic within the class. Or it could be that if the class is extending another one, then on the parent you'd have the protected new method, then on the child which you'd normally instantiate you can have the regular new method with parameters, however that would still not be static.

    msdn.microsoft.com/.../aa673265.aspx

    So your class should normally have these if it could be executed via a menu item, and depending on parametrization or what other frameworks does it extend (such as RunBase or SysOperation):

    - main

    - new

    - contruct

    - init

    - run

    - (validate)

    - (parm*)

    - (pack/unpack)

  • Community Member Profile Picture
    on at

    excellent

  • Community Member Profile Picture
    on at

    but why we should not use new method directly and instead use construct method  

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

    There often is a good reason to make the constructor protected and offer a public construct() method instead, therefore everybody is forced to call the static method instead of the constructor. For example, imagine that you've implemented a child class that you want to use instead of the parent class. You have to change all places where the constructor is used, which is trivial if the only place is in construct() instead of spread across the whole codebase.

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