Beispiel #1
0
        static void Main(string[] args)
        {
            //https://ppt-online.org/543101
            // https://stackify.com/solid-design-open-closed-principle/
            //Frequency and Effects of Changes

            //The argument for the single responsibility principle is relatively simple:
            //    it makes your software easier to implement
            //    and prevents unexpected side - effects of future changes.
            //requirements change over time and changes the responsibility of at least one class
            //more responsibilities more to change

            // Easier to Understand
            //Classes, software components and microservices that have only one responsibility are much easier to explain, understand and implement than the ones that provide a solution for everything
            //reduces the number of bugs
            //improves your development speed

            //not oversimplify your code
            //by creating classes with just one function
            //then you have to inject many dependencies which makes the code very unreadable and confusing
            //Therefore, the single responsibility principle is an important rule to make your code more understandable but don’t use it as your programming bible. Use common sense when developing code. There is no point in having multiple classes that just contain one function.

            //A Simple Question to Validate Your Design
            //What is the responsibility of your class/component/microservice?
            //If your answer includes the word “and”, you’re most likely breaking the single responsibility principle.

            Journal j = new Journal();

            j.AddEntry("Сегодня прекрасный день");
            j.AddEntry("Single responsibility principle");
            PersistanceManager persistanceManager = new PersistanceManager();

            persistanceManager.SaveToFile(j, "Filename.txt", true);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var journal = new Journal();

            journal.AddEntry("I am sad");
            journal.AddEntry("I ate a bug");

            System.Console.WriteLine(journal);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var j = new Journal();

            j.AddEntry("I cried today");
            j.AddEntry("I ate a bug");
            WriteLine(j);

            var p        = new Persistance();
            var filename = @"c:\temp\journal.txt";

            p.SaveToFile(j, filename, true);
            Process.Start(filename);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var j = new Journal();

            j.AddEntry("I cried today");
            j.AddEntry("I ate a bug");
            WriteLine(j);

            var p        = new Persistence();
            var filename = @"d:\DesignPatterNs\journal.txt";

            p.SaveToFile(j, filename);
            Process.Start(filename);//This code assumes the process you are starting will terminate itself.
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var j = new Journal();

            j.AddEntry("I cried today");
            j.AddEntry("I eat a bug");
            WriteLine(j.ToString());
            var p        = new Persistence();
            var filename = @"C:\Users\IGOR\source\repos\S.O.L.I.D\SRP\journal.txt";

            p.Save(j, filename, true);
            Process.Start(filename);
            Console.ReadLine();
        }