Single Responsibility Principle usage how can i call sub method correctly?

Posted by Phsika on Stack Overflow See other posts from Stack Overflow or by Phsika
Published on 2010-05-29T08:36:29Z Indexed on 2010/05/29 8:42 UTC
Read the original article Hit count: 350

Filed under:
|
|
|
|

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.RaporHazirla(wordraporu, "data");
            Console.ReadKey();
        }
    }

    interface IReportManager
    {
        void RaporHazirla(IReport rapor, string bilgi);
    }

    class ReportManager : IReportManager
    {
        public void RaporHazirla(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 yaratildi:{0}",bilgi);
        }

    }

    class ExcellRaporu : IReport
    {
        public void  RaporYarat(string bilgi)
        {
          Console.WriteLine("Excell raporu yaratildi:{0}",bilgi);
        }
}

    class PdfRaporu : IReport
    {
       public void  RaporYarat(string bilgi)
       {
         Console.WriteLine("pdf raporu yaratildi:{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.RaporHazirla(word,"test");
        }
    }
      interface IReportManager
    {
        void RaporHazirla(IReport rapor, string bilgi);
    }

    class ReportManager : IReportManager
    {
        public void RaporHazirla(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 yaratildi:{0}",bilgi);
        }

    }

    class ExcellRaporu : IReport
    {
        public void  RaporYarat(string bilgi)
        {
          Console.WriteLine("Excell raporu yaratildi:{0}",bilgi);
        }
}

    class PdfRaporu : IReport
    {
       public void  RaporYarat(string bilgi)
       {
         Console.WriteLine("pdf raporu yaratildi:{0}",bilgi);
       }
}
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET