i try to learn SOLID prencibles. i writed two type of code style. which one is :
1)Single Responsibility Principle_2.cs : if you look main program all instance generated from interface
1)Single Responsibility Principle_3.cs : if you look main program all instance genareted from normal class
My question: which one is correct usage? which one can i prefer?
namespace Single_Responsibility_Principle_2
{
class Program
{
static void Main(string[] args)
{
IReportManager raporcu = new ReportManager();
IReport wordraporu = new WordRaporu();
raporcu.RaporHazırla(wordraporu, "data");
Console.ReadKey();
}
}
interface IReportManager
{
void RaporHazırla(IReport rapor, string bilgi);
}
class ReportManager : IReportManager
{
public void RaporHazırla(IReport rapor, string bilgi)
{
rapor.RaporYarat(bilgi);
}
}
interface IReport
{
void RaporYarat(string bilgi);
}
class WordRaporu : IReport
{
public void RaporYarat(string bilgi)
{
Console.WriteLine("Word Raporu yaratıldı:{0}",bilgi);
}
}
class ExcellRaporu : IReport
{
public void RaporYarat(string bilgi)
{
Console.WriteLine("Excell raporu yaratıldı:{0}",bilgi);
}
}
class PdfRaporu : IReport
{
public void RaporYarat(string bilgi)
{
Console.WriteLine("pdf raporu yaratıldı:{0}",bilgi);
}
}
}
Second 0ne all instance genareted from normal class
namespace Single_Responsibility_Principle_3
{
class Program
{
static void Main(string[] args)
{
WordRaporu word = new WordRaporu();
ReportManager manager = new ReportManager();
manager.RaporHazırla(word,"test");
}
}
interface IReportManager
{
void RaporHazırla(IReport rapor, string bilgi);
}
class ReportManager : IReportManager
{
public void RaporHazırla(IReport rapor, string bilgi)
{
rapor.RaporYarat(bilgi);
}
}
interface IReport
{
void RaporYarat(string bilgi);
}
class WordRaporu : IReport
{
public void RaporYarat(string bilgi)
{
Console.WriteLine("Word Raporu yaratıldı:{0}",bilgi);
}
}
class ExcellRaporu : IReport
{
public void RaporYarat(string bilgi)
{
Console.WriteLine("Excell raporu yaratıldı:{0}",bilgi);
}
}
class PdfRaporu : IReport
{
public void RaporYarat(string bilgi)
{
Console.WriteLine("pdf raporu yaratıldı:{0}",bilgi);
}
}
}