为更好的访问他们的组织方法 [英] Organizing methods for better accessing them
本文介绍了为更好的访问他们的组织方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创造条件,有在我们的数据库中管理数据的所有方法的一般库。
I'm trying to create a general library which would have all methods for managing data on our database.
这库将有很多的方法,所以我会喜欢使其更有条理。我想它与下面的语法使用
This library will have a lot of methods so I would like to make it more organized. I would like it to be used with the following syntax.
db.setData().insertNewAccount(username, password);
db.modifyData().deleteAccount(username, password);
db.getData().getAccount();
我将如何让这样的工作,如果我对有关使用setData例如方法将会出现键入使用setData
How would I make it work like that if I type setData for example methods related to setData would show up.
推荐答案
如果你真的想这样做的,那么你可以做这样的事情(伪代码):
If you really want to do it that way, then you could do something like this (pseudo code):
class DataRepository
{
public SetDataHelper setData()
{ return new SetDataHelper(); }
public ModifyDataHelper modifyData()
{ return new ModifyDataHelper(); }
public GetDataHelper getData()
{ return new GetDataHelper(); }
}
class SetDataHelper
{
public void insertNewAccount(username, password) { ... }
}
class ModifyDataHelper
{
public void deleteAccount(username, password) { ... }
}
class GetDataHelper
{
public Account getAccount() { ... }
}
然后你可以做到这一点你这样,更流畅:
And then you could do it your way, more fluently:
var db = new DataRepository();
db.setData().insertNewAccount(username, password);
db.modifyData().deleteAccount(username, password);
db.getData().getAccount();
这篇关于为更好的访问他们的组织方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文