根据 Martin Fowler 的说法,“有些东西可以公开,但这并不意味着你已经发布了它。” 这是否意味着这样的事情:
public interface IRollsRoyceEngine
{
void Start();
void Stop();
String GenerateEngineReport();
}
public class RollsRoyceEngine : IRollsRoyceEngine
{
public bool EngineHasStarted { get; internal set; }
public bool EngineIsServiceable { get; internal set; }
#region Implementation of IRollsRoyceEngine
public void Start()
{
if (EngineCanBeStarted())
EngineHasStarted = true;
else
throw new InvalidOperationException("Engine can not be started at this time!");
}
public void Stop()
{
if (EngineCanBeStopped())
EngineHasStarted = false;
else
throw new InvalidOperationException("Engine can not be started at this time!");
}
public string GenerateEngineReport()
{
CheckEngineStatus();
return EngineIsServiceable ? "Engine is fine for now" : "Hmm...there may be some problem with the engine";
}
#endregion
#region Non published methods
public bool EngineCanBeStarted()
{
return EngineIsServiceable ? true : false;
}
public bool EngineCanBeStopped()
{
return EngineIsServiceable ? true : false;
}
public void CheckEngineStatus()
{
EngineIsServiceable = true;
//_EngineStatus = false;
}
#endregion
}
可以说这个发布的接口是IRollsRoyceEngine而不是RollsRoyceEngine中的任何东西吗?
如果是这样,公共方法和已发布方法之间的真正区别是什么?