外观设计模式和子类化
我正在为 C# 程序使用外观设计模式。程序基本上 看起来像这样...
public class Api
{
#region Constants
private const int version = 1;
#endregion
#region Private Data
private XProfile _profile;
private XMembership _membership;
private XRoles _role;
#endregion Private Data
public Api()
{
_membership = new XMembership();
_profile = new XProfile();
_role = new XRoles();
}
public int GetUserId(string name)
{
return _membership.GetIdByName(name);
}
}
现在,我想将我的方法分为三类:角色、配置文件和成员。 这对开发人员来说会更容易,因为 Profile 和 Membership 都公开了许多看起来相似的方法(还有一些按角色划分的方法)。例如,获取用户的 ID 看起来像:
int _id = Namespace.Api.Member.GetUserId("Henry222");
有人可以“说明”在这种情况下子类化应该如何工作以实现我正在寻找的效果吗?
提前致谢。
I am using a facade design pattern for a C# program. The program basically
looks like this...
public class Api
{
#region Constants
private const int version = 1;
#endregion
#region Private Data
private XProfile _profile;
private XMembership _membership;
private XRoles _role;
#endregion Private Data
public Api()
{
_membership = new XMembership();
_profile = new XProfile();
_role = new XRoles();
}
public int GetUserId(string name)
{
return _membership.GetIdByName(name);
}
}
Now, as I would like subclass my methods into three categories: Role, Profile, and Member.
This will be easier on the developers eye because both Profile and Membership expose a lot of methods that look similar (and a few by Role). For example, getting a user's ID would look like:
int _id = Namespace.Api.Member.GetUserId("Henry222");
Can somebody "illustrate" how subclassing should work in this case to achieve the effect I am looking for?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为从你的问题的上下文来看,你可能指的是“内部阶级”。您可以尝试类似以下的操作...
I would argue that you might mean "inner class" from the context of your question. You might try something like the following...