Question 68 of 103 from exam MB-500: Microsoft Dynamics 365: Finance and Operations Apps Developer

Question 68 of 103 from exam MB-500: Microsoft Dynamics 365: Finance and Operations Apps Developer

Question

HOTSPOT - You have a Dynamics 365 Finance environment.

You have the following code: (Line numbers are included for reference only.)

Ol class SalesPriceDiscount

02 ¢

03 eee

04 public void calculatePrice
os {

06

07 }

08 public static AmountCur getDiscount (Percent markup)
09 {

10

11 ,

12}

13 [ExtensionOf (classStr (SalesPriceDiscount) ) ]
14 final class SalesPriceDiscountMy_Extension
15 {

16 public void calculatePrice()

17 {

18 wee

19 next calculatePrice()

20 _

21 }

22 }

For each of the following statements, select Yes if the statement is true.

Otherwise, select No.

NOTE: Each correct selection is worth one point.

Hot Area:

Answer Area

Statement

The calculatePrice() method in the extension class can
access and manage public and protected methods and
variables of the base class.

You can modify the calculatePrice() method in the extension
class by adding conditional logic at line 20.

The static method getDiscount() in Line 10 of the base class
can be wrapped and extended by adding business logic to
the extension class.

The extension class can be instantiated by running the

following code:
SalesPriceDiscountMy Extension myInstance = new
SalesPriceDiscountMy_Extension();

Yes

No

Explanations

Answer Area

Statement

The calculatePrice() method in the extension class can
access and manage public and protected methods and
variables of the base class.

You can modify the calculatePrice() method in the extension
class by adding conditional logic at line 20.

The static method getDiscount() in Line 10 of the base class
can be wrapped and extended by adding business logic to
the extension class.

The extension class can be instantiated by running the

following code:
SalesPriceDiscountMy Extension myInstance = new
SalesPriceDiscountMy_Extension();

Yes

No

Box 1: Yes - Class extension - Method wrapping and Chain of Command.

The functionality for class extension, or class augmentation, has been improved.

You can now wrap logic around methods that are defined in the base class that you're augmenting.

You can extend the logic of public and protected methods without having to use event handlers.

When you wrap a method, you can also access public and protected methods, and variables of the base class.

In this way, you can start transactions and easily manage state variables that are associated with your class.

Box 2: Yes - In the following example, the wrapper around doSomething and the required use of the next keyword create a Chain of Command (CoC) for the method.

CoC is a design pattern where a request is handled by a series of receivers.

The pattern supports loose coupling of the sender and the receivers [ExtensionOf(classStr(BusinessLogic1))] final class BusinessLogic1_Extension { str doSomething(int arg) { // Part 1 var s = next doSomething(arg + 4); // Part 2 return s; } } Box 3: Yes - Instance and static methods can be wrapped by extension classes.

If a static method is the target that will be wrapped, the method in the extension must be qualified by using the static keyword.

Box 4: No - Wrapper methods must always call next.

Note: Wrapper methods in an extension class must always call next, so that the next method in the chain and, finally, the original implementation are always called.

This restriction helps guarantee that every method in the chain contributes to the result.

In the current implementation of this restriction, the call to next must be in the first-level statements in the method body.

Here are some important rules: -> Calls to next can't be done conditionally inside an if statement.

-> Calls to next can't be done in while, do-while, or for loop statements.

-> A next statement can't be preceded by a return statement.

-> Because logical expressions are optimized, calls to next can't occur in logical expressions.

At runtime, the execution of the complete expression isn't guaranteed.

https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/extensibility/method-wrapping-coc