我收到了另一个团队的api和一些代码片段。我不确定如何让ApiTest工作。前两个片段是提供给我的。最后一个是我尝试实现界面并使其正常工作......
using com.XXXX.api;
class ApiTest
{
static void Main(string[] args)
{
MicrositesApiFactory factory = MicrositesApiFactory.getInstance();
Logger logger = factory.getLogger("ApiTest", typeof(Program));
logger.error("created logger");
/*
if (logger.isTraceEnabled)
{
logger.trace("acquired logger successfully");
}
*/
DatabaseMgr databaseMgr = factory.getDatabaseMgr("microsites");
if (databaseMgr == null)
{
//logger.alert("unable to retrieve DatabaseMgr object");
}
else
{
DbConnection conn = databaseMgr.getDbConnection(DatabaseSchema.ApplicationSchema);
}
Console.In.ReadLine();
}
无论出于何种原因,他们在方法之后都包含了{...}。我不确定我需要在这做什么。 他们提供的界面:
namespace com.XXXX.api
{
public class MicrositesApiFactory
{
public static MicrositesApiFactory getInstance() {...}
public Logger getLogger(String msId, Type type) {...}
public DatabaseMgr getDatabaseMgr(String msId) {...}
}
public abstract class Logger
{
public String MicrositeId { get; set; }
public abstract void alert(String message);
}
public enum DatabaseSchema
{
ApplicationSchema,
ConsumerSchema,
ContentSchema
}
public abstract class DatabaseMgr
{
public String MicrositeId { get; set; }
protected DatabaseMgr(String micrositeId) { ... }
public abstract DbConnection
getDbConnection(DatabaseSchema schema);
}
}
以下是我对界面的改编以使其正常工作。 我不知道最好的办法是什么。 根据我对Interfaces的理解,我需要实现所有方法。 任何关于实现接口的建议都是受欢迎的。
此错误是唯一剩下的错误:
DatabaseMgr不包含带0参数的构造函数
using System;
using System.Data.Common;
using System.Data.SqlClient;
namespace com.tsystems_mms.phi.microsites.api
{
public class MicrositesApiFactory : Logger
{
public override DbConnection getDbConnection(DatabaseSchema message)
{
DbConnection test = new SqlConnection();
return test;
}
public DatabaseMgr getDatabaseMgr(String msId)
{
DatabaseMgr test = new MicrositesApiFactory();
return test;
}
public static MicrositesApiFactory getInstance() {
return new MicrositesApiFactory();
}
public override void alert(string message) { }
public override bool isErrorEnabled
{
get { throw new NotImplementedException(); }
}
public Logger getLogger(String msId, Type type)
{
Logger test = new MicrositesApiFactory();
return test;
}
}
public abstract class Logger : DatabaseMgr
{
public new String MicrositeId { get; set; }
public abstract void alert(String message);
public abstract bool isErrorEnabled { get; }
}
public enum DatabaseSchema
{
ApplicationSchema,
ConsumerSchema,
ContentSchema
}
public abstract class DatabaseMgr
{
public String MicrositeId { get; set; }
protected DatabaseMgr(String micrositeId)
{
}
public abstract DbConnection getDbConnection(DatabaseSchema schema);
}
}