i writed some codes about oop pattern. But i cannot see clearly these two kind of usage advantage disadvantagages:
Firs one:
class Program
{
static void Main(string[] args)
{
Report rp = new Report();
rp.MakeReport();
rp = new ExcelReport();
rp.MakeReport();
rp = new PdfReport();
rp.MakeReport();
rp = new WordReport();
rp.MakeReport();
Console.ReadKey();
}
}
Second usage
class Program
{
static void Main(string[] args)
{
Report[] rp = new Report[4];
rp[0] = new Report();
rp[1] = new ExcelReport();
rp[2] = new PdfReport();
rp[3] = new WordReport();
rp[0].MakeReport();
rp[1].MakeReport();
rp[2].MakeReport();
rp[3].MakeReport();
Console.ReadKey();
}
}
Class stracture:
class Report
{
public virtual void MakeReport()
{
Console.WriteLine("Simple Report preparing...");
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Simple Report prepared...");
}
}
class ExcelReport : Report
{
public override void MakeReport()
{
Console.WriteLine("Excel Report preparing...");
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Excel Report prepared...");
}
}
class PdfReport : Report
{
public override void MakeReport()
{
Console.WriteLine("Pdf Report preparing...");
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Pdf Report prepared...");
}
}
class WordReport : Report
{
public override void MakeReport()
{
Console.WriteLine("Word Report preparing...");
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Word Report prepared...");
}
}
What is the difference first one and second one? which one can i prefer ? what kind of stuation can i use one of them? What is adv or disAdv between two kind of usage?