В следующем родительском классе SqlStatement , как я могу сделать Initialize () abstract , но сохранить Execute () виртуальный
using System;
using System.Collections.Generic;
namespace TestSql28374
{
class Program
{
static void Main(string[] args)
{
object item = new object();
List<string> properties = new List<string>();
SqlCreateStatement sqlCreateStatement = new SqlCreateStatement(properties);
sqlCreateStatement.Execute();
SqlInsertStatement sqlInsertStatement = new SqlInsertStatement(item, properties);
sqlInsertStatement.Execute();
Console.ReadLine();
}
}
public class SqlStatement
{
protected List<string> properties;
protected object item;
protected string sql;
public SqlStatement(List<string> properties)
{
this.properties = properties;
}
protected virtual void Initialize() //should be abstract
{ }
public virtual void Execute()
{
Console.WriteLine("Sending to database: " + sql);
}
}
public class SqlCreateStatement : SqlStatement
{
public SqlCreateStatement(List<string> properties)
: base(properties)
{
Initialize();
}
protected override void Initialize()
{
sql = "CREATE TABLE...";
}
}
public class SqlInsertStatement : SqlStatement
{
public SqlInsertStatement(object item, List<string> properties)
: base(properties)
{
this.item = item;
Initialize();
}
protected override void Initialize()
{
sql = "INSERT INTO...";
}
}
}