using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 外观模式
{
//登录名
public class LoginName
{
public string Name;
public LoginName(string name)
{
this.Name = name;
}
public bool CheckName()
{
Console.WriteLine("登录名{0}存在", Name);
return true;
}
}
//登录密码
public class LoginPassword
{
public string Password;
public LoginPassword(string password)
{
this.Password = password;
}
public bool CheckPassword()
{
Console.WriteLine("密码{0}正确", Password);
return true;
}
}
//判断登录是否成功
public class LoginCheck
{
public LoginName loginname;
public LoginPassword loginpassword;
public LoginCheck(string name,string password)
{
loginname = new LoginName(name);
loginpassword = new LoginPassword(password);
}
public bool Login()
{
if (loginname.CheckName())
{
return loginpassword.CheckPassword();
}
return false;
}
}
class Program
{
static void Main(string[] args)
{
LoginCheck logincheck = new LoginCheck("dwm", "123456");
if(logincheck.Login())
{
Console.WriteLine("登录成功!");
}
else
{
Console.WriteLine("登录失败!");
}
Console.ReadKey();
}
}
}
c# 外观模式简单例子
最新推荐文章于 2024-09-05 10:16:53 发布