Replaceable methods


Chain of command enables wrapping of methods – but you must call next. This ensure the "chain" is not broken, and everyone wrapping the method will indeed be called.

However, sometimes it makes sense to break the chain. Here are some examples where this could be useful:

  • In lookup methods. The base implementation will open a lookup dialog, anyone wrapping will (likely) also open a dialog. Yet the user only expects one lookup.
  • In methods with complex SQL operations. As of now; there are select statements (including delete_from, update_recordset, insert_recordset) we cannot make extensible. One way to work around the limitation is to move the statement to a dedicated method, and make the method replaceable.
  • In conversion methods. Here you can conditionally call next, to skip the base conversion, if your logic can handle the conversion.

In Platform Update 11 – we can now decorate methods with the [Replaceable] attribute. This will relax the compiler, so it doesn't look for the next keyword. Logically, this means that when wrapping a Replaceable method, there is no guarantee that your logic will fire. Someone else might be replacing the method, and breaking the chain.

The author of the code is still in control of which methods are replaceable.

My dear "partner in crime" Vanya Kashperuk has written a great post about the new capability here: http://kashperuk.blogspot.dk/2017/10/development-tutorial-extensibility_7.html

 

 


Comments (0)

Skip to main content