Also, the provider Mode

Source: Internet
Author: User

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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.