dynamics-crm-2011dynamics-crmdynamics-crm-2013dynamics-crm-2015

Why the plugins implement IPlugin interface and Workflows (custom) inherits the Code Activity base class


Basically i have been asked this question in an interview, and i answered it partially by saying that,

You can create your own custom workflow activity base class by deriving the CodeActivity abstract class and add your organization (business) specific components in it, e.g. logging and exception handling mechanisms.

Now any custom workflow activity you create you will derive the newly created custom workflow activity base class, and all the base class features will be available.

But the same is the case with interfaces, hence why IPlugin is an interface and not an abstract class for instance PluginBase.


Solution

  • As CodeActivity have 35 methods, it seems logical to make it abstract class so that developer have flexibility to implement the method/methods on his choice/requirement in the class inheriting CodeActivity. If CodeActivity was an interface, it become mandatory to implement all the 35 methods in class implementing interface which is illogical. That’s why Microsoft made CodeActivity as abstract class while Iplugin as Interface.