0
尝试创建一个简单的noddy示例,以便我可以使用流畅接口构建我的下一个项目。 我需要为我的dll的用户提供一个直观的逐步构建类的方式。流畅的流畅界面如何在开始时隐藏所有方法,但只有一个?
问题。 我想用户只能看到初始化时,第一次启动然后step1然后step2 然后结束?我该怎么做?
这是我的尝试,只要你把“。”你看到了一切,然后他们隐藏起来。
class Program
{
static void Main(string[] args)
{
IEnd builder = new StepBuilder()
.Initialize()
.LoadStuff()
.Validate()
.End();
}
}
public class StepBuilder : IInitialize,
IStep1,
IStep2,
IStep3,
IEnd
{
public IStep1 Initialize()
{
return this;
}
public IStep2 LoadStuff()
{
return this; ;
}
public IStep3 Validate()
{
return this;
}
public IEnd End()
{
return this;
}
public bool Save()
{
return true;
}
}
public class Step
{
public string Name { get; set; }
public string Category { get; set; }
public decimal Price { get; set; }
}
public interface IInitialize
{
IStep1 Initialize();
}
public interface IStep1
{
IStep2 LoadStuff();
}
public interface IStep2
{
IStep3 Validate();
}
public interface IStep3
{
IEnd End();
}
public interface IEnd
{
bool Save();
}
}
建设逐步流利接口的任何建议或好的链接?
感谢您的回复,听起来good.How将是改变接口的其余喜?这是否意味着我的IStep1初始化会消失? – user9969
刚刚尝试过,但之后,我看到everything.I认为我错过了明显的。任何时间使用我提供的接口的小例子。很多谢谢 – user9969
感谢现在很多都清楚。 – user9969