Compartilhar via


Use the Type System Design Pattern

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

X++ is a type-strong language. It is a best practice to fully exploit the Microsoft Dynamics AX Type system.

Situation

Implement code that is type-safe rather than type-unsafe.

Solution

Always code in a strongly typed manner—define, declare, and use specific types. Do not use general types. Create and use specialized types for any special situation.

Use types that are as specialized as possible. This helps identify problems at compile time, leaving as few problems as possible to be found at run time.

Always use the root types Object, Common, and str with great care as follows:

  • Used members – have no compile-time checking

  • str – has no compile-time or run-time checks of length-compatibility

  • str – avoid using in any business-specific situation

Take care when you work with unstructured types, such as anytype, container, and struct. Use unstructured types only if there is no better alternative.

Do not write or call lots of code to validate data where the type system or other supporting systems already guarantee that everything is functioning correctly. This affects run-time resources and wastes development time.

See also

Microsoft Dynamics AX Design Patterns

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.