- Статические методы
- Посредством создания экземпляров
- Смесь вышеперечисленного, но с передачей
полного родительского класса в класс зависимостей (имеет ли это влияние на память
или нет, потому что это просто указатель?)
Код: Выделить всё
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;
}
}
}
Кроме того, какое отношение ко всему этому имеют внедрение зависимостей и интерфейсы? Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/748 ... -principle