浏览代码

门面模式(继续完善)

jeffrey 8 年之前
父节点
当前提交
76cf4b5c11

+ 6 - 0
DesignPattern.sln

@@ -31,6 +31,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompositePattern", "Composi
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObserverPattern", "ObserverPattern\ObserverPattern.csproj", "{4C79FD56-5B6A-44A6-A2F1-4F5DBCAEC907}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FacadePattern", "FacadePattern\FacadePattern.csproj", "{CA00E48A-FCA2-44F1-A7C3-DF89FD3802BE}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -93,6 +95,10 @@ Global
 		{4C79FD56-5B6A-44A6-A2F1-4F5DBCAEC907}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{4C79FD56-5B6A-44A6-A2F1-4F5DBCAEC907}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{4C79FD56-5B6A-44A6-A2F1-4F5DBCAEC907}.Release|Any CPU.Build.0 = Release|Any CPU
+		{CA00E48A-FCA2-44F1-A7C3-DF89FD3802BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{CA00E48A-FCA2-44F1-A7C3-DF89FD3802BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{CA00E48A-FCA2-44F1-A7C3-DF89FD3802BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{CA00E48A-FCA2-44F1-A7C3-DF89FD3802BE}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 12 - 0
FacadePattern/ATM.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FacadePattern
+{
+    class ATM
+    {
+    }
+}

+ 23 - 0
FacadePattern/AccountVerificationCenter.cs

@@ -0,0 +1,23 @@
+using System.Collections.Generic;
+
+namespace FacadePattern
+{
+    /// <summary>
+    ///     银行账户验证中心
+    /// </summary>
+    public class AccountVerificationCenter
+    {
+        private readonly List<BankAccount> accounts = new List<BankAccount>
+        {
+            new BankAccount("123456789012345", "555555", "圣杰", "135****9309", 1000000),
+            new BankAccount("123456789012346", "222222", "Jeffrey", "135****9309", 2000000),
+            new BankAccount("123456789012347", "333333", "Shengjie", "135****9309", 3000000),
+            new BankAccount("123456789012348", "777777", "程序猿", "135****9309", 4000000),
+            new BankAccount("123456789012349", "888888", "设计狮", "135****9309", 5000000)
+        };
+
+        public void Verify(string bankNo, string password)
+        {
+        }
+    }
+}

+ 6 - 0
FacadePattern/App.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
+    </startup>
+</configuration>

+ 32 - 0
FacadePattern/Bank.cs

@@ -0,0 +1,32 @@
+using System;
+
+namespace FacadePattern
+{
+    public class Bank : IBank
+    {
+        /// <summary>
+        ///     查询余额
+        /// </summary>
+        /// <param name="account">银行账户</param>
+        /// <returns></returns>
+        public int CheckBalance(BankAccount account)
+        {
+            throw new NotImplementedException();
+        }
+
+        public int WithdrewMoney(BankAccount account, int money)
+        {
+            throw new NotImplementedException();
+        }
+
+        public int DepositMoney(BankAccount account, int money)
+        {
+            throw new NotImplementedException();
+        }
+
+        public int TransferMoney(BankAccount account, BankAccount targetAccount, int money)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 39 - 0
FacadePattern/BankAccount.cs

@@ -0,0 +1,39 @@
+namespace FacadePattern
+{
+    public class BankAccount
+    {
+        public BankAccount(string bankNo, string password, string name, string phone, int totalMoney)
+        {
+            BankNo = bankNo;
+            Password = password;
+            Name = name;
+            Phone = phone;
+            TotalMoney = totalMoney;
+        }
+
+        /// <summary>
+        ///     银行卡号
+        /// </summary>
+        public string BankNo { get; set; }
+
+        /// <summary>
+        ///     取款密码
+        /// </summary>
+        public string Password { get; set; }
+
+        /// <summary>
+        ///     持卡人姓名
+        /// </summary>
+        public string Name { get; set; }
+
+        /// <summary>
+        ///     手机
+        /// </summary>
+        public string Phone { get; set; }
+
+        /// <summary>
+        ///     总金额
+        /// </summary>
+        public int TotalMoney { get; set; }
+    }
+}

+ 65 - 0
FacadePattern/FacadePattern.csproj

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{CA00E48A-FCA2-44F1-A7C3-DF89FD3802BE}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>FacadePattern</RootNamespace>
+    <AssemblyName>FacadePattern</AssemblyName>
+    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="AccountVerificationCenter.cs" />
+    <Compile Include="ATM.cs" />
+    <Compile Include="Bank.cs" />
+    <Compile Include="BankAccount.cs" />
+    <Compile Include="IBank.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 37 - 0
FacadePattern/IBank.cs

@@ -0,0 +1,37 @@
+namespace FacadePattern
+{
+    public interface IBank
+    {
+        /// <summary>
+        ///     查询余额
+        /// </summary>
+        /// <param name="account">银行账户</param>
+        /// <returns></returns>
+        int CheckBalance(BankAccount account);
+
+        /// <summary>
+        ///     取款
+        /// </summary>
+        /// <param name="account">银行账户</param>
+        /// <param name="money">取多少钱</param>
+        /// <returns></returns>
+        int WithdrewMoney(BankAccount account, int money);
+
+        /// <summary>
+        ///     存款
+        /// </summary>
+        /// <param name="account">银行账户</param>
+        /// <param name="money">存多少钱</param>
+        /// <returns></returns>
+        int DepositMoney(BankAccount account, int money);
+
+        /// <summary>
+        ///     转账
+        /// </summary>
+        /// <param name="account">转出账户</param>
+        /// <param name="targetAccount">目标账户</param>
+        /// <param name="money">转多少钱</param>
+        /// <returns></returns>
+        int TransferMoney(BankAccount account, BankAccount targetAccount, int money);
+    }
+}

+ 15 - 0
FacadePattern/Program.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FacadePattern
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+        }
+    }
+}

+ 36 - 0
FacadePattern/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("FacadePattern")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("FacadePattern")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//将 ComVisible 设置为 false 将使此程序集中的类型
+//对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("ca00e48a-fca2-44f1-a7c3-df89fd3802be")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]