Answer the question
In order to leave comments, you need to log in
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();
});
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question