The code I've inherited has a design that I'm not familiar with (I'm still new to the world of programming).
It is a .net project and there are 3 classes in question here.
public Class1
{
public void DoSomething()
{
Class2 class2 = new Class2();
string myValue = class2.GetSomeValuePlease();
//why would I not do class2.MyClass3.GetActualValue();
}
}
public Class2
{
public Class3 MyClass3 = new Class3();
public string GetSomeValuePlease()
{
return this.MyClass3.TheActualValue();
}
}
public Class3
{
public string TheActualValue()
{
return "This is the value";
}
}
As you can see, all 3 classes are public. I don't understand why, using the example above, I would use Class2 at all? I could understand if within the GetSomeValuePlease()
method there was some logic which affected Class2, but there isn't.
Normally, I'd just go ahead and remove the Class2 method (GetSomeValuePlease) and call Class3 method (GetActualValue) direct from Class1, but, the developer I took over (who is not contactable) is wiser and more experienced than I. I have a feeling this is just over engineering and this is just extra code / extra maintenance.
Does any one have experience in designing this way that could explain the thought process or implications of having this "middle class" vs going direct?
Class1
to know aboutClass3
.c#
code, you don't needreturn = value;
, rather justreturn value;
.Class3 MyClass3 = new Class
did you mean to writeClass3 MyClass3 = new Class3
?