根據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?
如果是這樣,公共方法和已發佈方法的真正區別是什麼?
有關此問題的更多信息,請訪問http://martinfowler.com/ieeeSoftware/published.pdf – 2008-12-14 08:11:24