Actually, after I learned about the business object class businessbase, I still have a blank brain and I am not doing enough internal work. Check how blogengine.net processes data.
The provider mode is actually the policy mode: defines the algorithm family and encapsulates them separately so that they can replace each other. This mode makes the algorithm changes independent of the customers who use the algorithm.
Let's look at how blogengine.net is implemented.
Looking at the face-to-face class diagram, two provider classes, one operation XML, and one operation database are implemented. The policy pattern is defined as an algorithm encapsulated separately and can be replaced with each other.
How is that independent of customers who use algorithms?
Blogengine.net defines a static class for the client to use. Here, a loadproviders method is used to load the provider (XML... or DB ..)
Loadproviders
1 ///<summary>
2 /// Load the providers from the web.config.
3 ///</summary>
4 private static void LoadProviders()
5 {
6 // Avoid claiming lock if providers are already loaded
7 if (_provider == null)
8 {
9 lock (TheLock)
10 {
11 // Do this again to make sure _provider is still null
12 if (_provider == null)
13 {
14 // Get a reference to the <blogProvider> section
15 var section = (BlogProviderSection)WebConfigurationManager.GetSection("BlogEngine/blogProvider");
16
17 // Load registered providers and point _provider
18 // to the default provider
19 _providers = new BlogProviderCollection();
20 ProvidersHelper.InstantiateProviders(section.Providers, _providers, typeof(BlogProvider));
21 _provider = _providers[section.DefaultProvider];
22
23 if (_provider == null)
24 {
25 throw new ProviderException("Unable to load default BlogProvider");
26 }
27 }
28 }
29 }
30 }
Blogprovider
<BlogEngine>
<blogProvider defaultProvider="XmlBlogProvider">
<providers>
<add name="XmlBlogProvider" type="BlogEngine.Core.Providers.XmlBlogProvider, BlogEngine.Core"/>
<add name="DbBlogProvider" type="BlogEngine.Core.Providers.DbBlogProvider, BlogEngine.Core" connectionStringName="BlogEngine"/>
</providers>
</blogProvider>
</BlogEngine>
You can see that the configuration file is read for loading.
Now we know that the client does not need to know whether the provider in blogservice is xmlblogprovider or dbblogprovider. We only need to call its method for crud. The data source will be changed later,
Add xxxblogprovider and modify the configuration file. No client code is required.