我可以使用什么模式来编写 CRUD 功能?
What pattern can I use to write CRUD functionality?
我正在编写控制台应用程序。 CRUD functionality.I 想尝试应用该模式。是否可以应用 "state" 模式?在AddCustomer()方法最后,调用了InputMenu()方法,我认为这是不正确的。
static void Main(string[] args)
{
DataFunction dataFunction = new DataFunction();
dataFunction.InputMenu();
}
public void InputMenu()
{
Console.WriteLine("Add Customer? --- 1, Remove customer? --- 2, Show All Customer? --- 3");
string _value = Console.ReadLine();
switch (_value)
{
case "1":
AddCustomer();
break;
case "2":
RemoveCustomer();
break;
case "3":
ShowAllCustomers();
break;
default:
Console.WriteLine("You clicked an unknown letter");
break;
}
public void AddCustomer()
{
Console.WriteLine("Input Name");
string _name = Console.ReadLine();
Console.WriteLine("Input Adress");
string _adress = Console.ReadLine();
_dataContext.Customers.Add(
new Customer
{
Name = _name,
Adress = _adress
});
_dataContext.SaveChanges();
InputMenu();
}
我想重新制作"InputMenu",是否可以应用状态模式?
首先,将您的业务逻辑放在不同的层上是一个很好的做法,如果需要,您可以重复使用代码,例如,将您的逻辑暴露在 RESTFul 或GraphQL API。一个非常实用的方法是使用 Clean Architecture.
我的观点是,专注于您的业务核心(实体 + 用例),遵循依赖性规则,在存储库层上对您的数据库访问进行编码,并为了提高工作效率,使用 ORM(Entity Framework ).
我正在编写控制台应用程序。 CRUD functionality.I 想尝试应用该模式。是否可以应用 "state" 模式?在AddCustomer()方法最后,调用了InputMenu()方法,我认为这是不正确的。
static void Main(string[] args)
{
DataFunction dataFunction = new DataFunction();
dataFunction.InputMenu();
}
public void InputMenu()
{
Console.WriteLine("Add Customer? --- 1, Remove customer? --- 2, Show All Customer? --- 3");
string _value = Console.ReadLine();
switch (_value)
{
case "1":
AddCustomer();
break;
case "2":
RemoveCustomer();
break;
case "3":
ShowAllCustomers();
break;
default:
Console.WriteLine("You clicked an unknown letter");
break;
}
public void AddCustomer()
{
Console.WriteLine("Input Name");
string _name = Console.ReadLine();
Console.WriteLine("Input Adress");
string _adress = Console.ReadLine();
_dataContext.Customers.Add(
new Customer
{
Name = _name,
Adress = _adress
});
_dataContext.SaveChanges();
InputMenu();
}
我想重新制作"InputMenu",是否可以应用状态模式?
首先,将您的业务逻辑放在不同的层上是一个很好的做法,如果需要,您可以重复使用代码,例如,将您的逻辑暴露在 RESTFul 或GraphQL API。一个非常实用的方法是使用 Clean Architecture.
我的观点是,专注于您的业务核心(实体 + 用例),遵循依赖性规则,在存储库层上对您的数据库访问进行编码,并为了提高工作效率,使用 ORM(Entity Framework ).