Can someone define for me the conceptual difference is between a Provider, Service and Broker?
I regularly write MVC apps and offload much of the business logic to other classes. Nothing fancy, just pass in parameters and receive back POCO instance(s).
What is a correct label to give those classes performing the heavy lifting for my controller(s)?
A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem in object-oriented systems. It describes the problem, the solution, when to apply the solution, and its consequences. It also gives implementation hints and examples.
A Provider is really just another name for the Strategy Pattern
Typically when someone mentions the use of a provider they are talking about some abstract contract to which many implementations could exist.
//As an abstract base class
public void SetupRoles(RoleProvider provider){}
//As an interface
public void SetupRoles(IRoleProvider provider){}
//As a delegate
public void SetupRoles(Action<String> addRole){}
A Service is usually meant to indicate a stateless object that has only methods on it. A service could be used as a Strategy, but doesn't necessarily have to be.
//Plain old service... doesn't even need the web
// CRAZY TALK MAN!!!
public static class RoleService
{
public static void SetupRoles(){};
public static String[] GetRoles(){};
}
A Broker is really just responsible for well... brokering. It is designed to move messages between services and objects, orchestrating the interactions between services in order to keep them isolated.
public class Broker
{
public void SendImportantMessage(Message msg)
{
//Do some important processing here
// Maybe some validation
NotifySomeOtherServiceOrClassOrMaybeBobFromAccounting(msg);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With