V
V
Vladislav_Bochkarev2020-07-31 14:22:37
OOP
Vladislav_Bochkarev, 2020-07-31 14:22:37

What OOP principles does this approach violate?

namespace TemporaryProj
{
    class SomeClassImpl
    {
        public int Field = 5;
        public string str = "I am hidden a lot!";
        public void SayHello()
        {
            Console.WriteLine("Hi dear!");
        }
    }
    class SomeClass
    {
        protected SomeClassImpl impl = new SomeClassImpl();
        public void GetAccessIfItIsImportant(Action<SomeClassImpl> action)
        {
            action?.Invoke(impl);
        }
    }
        class TmpProj
        {
        static void Main(string[] args)
        {
            SomeClass some = new SomeClass();
            some.GetAccessIfItIsImportant((SomeClassImpl impl) => 
            {
                impl.Field = 40;
                Console.WriteLine(impl.str + impl.Field);
                impl.SayHello();
            });
        }

        }
    }


Often when I use the Bridge pattern, I have to do this type of implementation fiddling.
I understand, of course, that this is not correct, but it is very convenient to use such an approach of "trust" to a programmer from the outside, who wants to tweak the implementation in some special cases.
Is it just right?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question