I don't think that simply using static methods makes it Functional
I don't think simply moving your previously static methods to a class makes it OO
If you are doing OO, then your classes should have properties and the methods should change those properties. This makes the 'data object' mutable and functional programming goes out the window
While Static does stop you using properties from the same class, you can still reference other static data or databases etc. Functional programming relies on your methods returning the same result for the same parameters every time.
Going from your Example code:
ive followed your pattern but added a real method
public class MyType
{
public int ANumber { get; set; }
}
public class StaticFunctions
{
public static int AddOne(MyType x)
{
return x.ANumber + 1;
}
}
so you convert your static method to OO via this kind of pattern:
public class MyOOClass
{
public MyType data { get; private set; }
public MyOOClass(MyType data)
{ this.data = data; }
public int AddOne()
{
return this.data.ANumber + 1;
}
}
But really this is nothing more than a namespace for your static functions. it arguably makes them harder to use as you have to initiate an extra MyOOClass for every MyType.
If you wanted to make it OO I would change it to something like this:
public class OOClass
{
public int ANumber { get; private set; }
public OOClass(int n)
{
this.ANumber = n;
}
public void AddOne()
{
this.ANumber= this.ANumber+1;
}
}
if you wanted to make it functional i would change it to something like this:
public Func<int, int> AddOne = (x) => x + 1;
My Personal fave though would be ADM
public class AdditionService()
{
public MyType AddOne(MyType a)
{
return new MyType() {ANumber=a.ANumber+1};
}
}