The core concept of the provider design mode is that the portal program transfers a service interface provided externally to different providers for implementation. The selected provider does not implement the service by inheriting the service interface, it is implemented through another independent inheritance path. compared with the interface inheritance implementation mode, the provider mode provides more scalability and flexibility.
Public abstract class providerbase
{
Protected string name;
Protected string description;
Public string name {Get ;}
Public String description {Get ;}
Public abstract void initialize ();
}
Public abstract class storeprovider: providerbase
{
Public abstract void addproducttostore ();
}
Public class cornerstoreprovider: storeprovider
{
Public override void initialize ()
{
Throw new notimplementedexception ();
}
Public override void addproducttostore ()
{
Throw new notimplementedexception ();
}
}
Public class vendingmachinestoreprovider: storeprovider
{
Public override void initialize ()
{
Throw new notimplementedexception ();
}
Public override void addproducttostore ()
{
Throw new notimplementedexception ();
}
}
Public static class store
{
Static store ()
{
Provider = new cornerstoreprovider ();
}
Static storeprovider provider;
Public static storeprovider provider {get {return provider ;}}
Public static void addproducttostore ()
{
Return provider. addproducttostore ();
}
}
Public class Program
{
Public void clientcoding ()
{
// Client code
Store. addproducttostore ();
}
}