Microsoft D365FO (Dynamics 365 Finance and Operations ERP) Introduction to X++ classes March 2025 guide which you can define using your X++ IDE described in Chapter 1 are to declare your data and help you make objects by instantiating an instance of the class which is creating an object. Data that you are defining in your class is a representation of the state of your object instance and these are usually stored in containers known as variables inside your class.
Classes may have x++ methods as well which help the object take actions of your choosing. You may have heard of the concept of functions. When they are members of a class or in other words are as if the functions belong to a class then these types of functions are usually instead known as methods like in x++.
The first main part of a class is called the declaration of your class. What your class declaration does is in x++ syntax it has your instance variables, the name of your class, and things like that. When it comes to X++ validation and declaration all of your classes are by default considered public even if the word “public” doesn’t explicitly appear in the declaration itself.
Private means your variables and methods can only be accessed from the same class you are currently in.
Protected means variables and methods may be accessed from the same class, or from any classes which are inheriting from or extending the class the protected member was declared in.
Public means that variables and methods may be accessed from not just this class or subclasses, but any class, hence public.
When you wonder what is the default access control in x++ access modifiers for your data member, class member and variables the answer is that it’s x++ default public access for class itself with no access modifier, default protected access for class members with no access modifier which means if you do not specify a particular access modifier explicitly for your x++ classes it means the default is public, in other words it’s accessible from any part of your Dynamics 365 Finance and Operations app. If you leave out the access control modifier from any of the class members such as instance variables, or method declarations inside your class, the default for those is protected (only accessible within class itself, or the class’s descendants). X++ access control defaults when you leave out the keyword may be quite different than for example C# default access control which is internal at class level (“internal” is slightly more permissive than “private”, allows access within same assembly, including with inheritance and with type – which private does not allow any access outside the same class – not even from the same assembly) rather than public by default for top level classes as well as structs, and for members like variables, even nested types default to private rather than public. x++ vs c# access control essentially is that in x++, leaving out the access control modifier suddenly makes everything the most permissive for classes (public) and very pretty permissive for all members (protected), but in C#, it’s pretty much almost the exact opposite (with the slight nuance of “internal” and not the true opposite of “private” for top level classes and structs), but essentially it is almost the most restricted kind of access you could possibly declare for that thing (except internal for class, since private more restricted than internal).
You of course are still able to individually control your accessibility of any particular methods inside your classes by leveraging access modifiers including protected, public and private. It is considered a best practice to go ahead and explicitly provide one of these modifiers anyway in call cases so the accessibility of your classes and members ends up being very clear and easy to understand rather than relying on default behaviors which may vary across different programming languages, so it may be confusing and error prone.
Have a Question ?
Fill out this short form, one of our Experts will contact you soon.
Call Us Today For Your Free Consultation
Call Now