I'm a hobby coder trying to improve my code. I tend to create monolithic classes and want to start being more the S in SOLID. I've done some reading on here and elsewhere, but I'm struggling to get my head around what the best approach to doing this is. I can think of three scenarios:
- Static Methods
- Through instantiation
- Mixture of above but passing full parent class to dependency class (does this have memory implications or not due to it just being a pointer?)
namespace SingleResponsabilityTest
{
internal class Program
{
static void Main(string[] args)
{
Factoriser factoriser = new Factoriser();
factoriser.DoFactorTen();
}
}
internal class Factoriser
{
public int classSpecificInt = 10;
public void DoFactorTen()
{
SingleResponsabiltyApproach1 sra1 = new SingleResponsabiltyApproach1(classSpecificInt);
Console.WriteLine(sra1.FactorTen());
Console.WriteLine(SingleResponsabiltyApproach2.FactorTen(classSpecificInt));
Console.WriteLine(SingleResponsabiltyApproach3.FactorTen(this));
Console.ReadLine();
}
}
internal class SingleResponsabiltyApproach1
{
int passedInt = 0;
public SingleResponsabiltyApproach1(int passedInt)
{
this.passedInt = passedInt;
}
public int FactorTen()
{
return passedInt * 10;
}
}
internal class SingleResponsabiltyApproach2
{
public static int FactorTen(int passedInt)
{
return passedInt * 10;
}
}
internal class SingleResponsabiltyApproach3
{
public static int FactorTen(Factoriser factoriser)
{
return factoriser.classSpecificInt * 10;
}
}
}
What is the best approach?
Also, where does dependency injection and interfaces come into all this? Thanks.