public class Service : IService
{
internal Configuration configuration;
public Response response;
public Service()
{
configuration = new Configuration();
configuration.Fetch();
}
public Response Execute(Request request)
{
switch case request.processtype
{
case ProcessType.Import:
Import import = new Import();
import.Configuration = configuration;
Response response = import.Execute(request)
case ProcessType.Export:
Export export = new Export();
export.Configuration = configuration;
Response response = export.Execute(request)
}
}
public class Import
{
public Configuration configuration;
public Response response;
public Response Execute(Request request)
{
response.AddMessage("doing something");
//some code
ImportSomething something = new ImportSomething();
something.Configuration = configuration;
something.Response = response;
response.AddMessage("doing more thing");
//more code
ImportSomethingElse somethingelse = new ImportSomethingElse();
somethingelse.Configuration = configuration;
somethingelse.Response = response;
return response;
}
public class ImportSomething
{
public Configuration configuration;
public Response response;
public Response Execute(Request request)
{
response.AddMessage("doing something");
//some code
response.AddMessage("doing more thing");
//more code
}
}
public class ImportSomethingElse
{
public Configuration configuration;
public Response response;
public Response Execute(Request request)
{
response.AddMessage("doing something");
//some code
response.AddMessage("doing more thing");
//more code
}
}
}
public class Export
{
public Configuration configuration;
public Response Execute(Request request)
{
}
}
public class Configuration
{
List<NameValue> Items;
public void Fetch()
{
//fetch from database
Items.Add("data");
}
}
public class Response
{
List<Message> Messages;
Public string Data;
public void AddMessage()
{
}
}
}
你會注意到我將配置和響應對象傳遞給我打電話的類。我想知道這是否正確。特別是我傳遞給每個類的響應對象是因爲最終響應需要包含來自所有對象的消息。c#類的設計問題
我從來沒有聽說過工廠。我正在研究它。如果你能指出我正確的方向,我將不勝感激。謝謝 – gangt