Methods should include the state needed to execute them as parameters

I’ve been seeing the following pattern in code that I’ve been working on lately.

var muhClass = new MuhClass();
muhClass.MuhProp = "foo";
muhClass.MuhOtherProp = "bar";

muhClass.MuhMethod();


public class MuhClass {

public string MuhProp {get; set; }
public string MyOtherProp {get; set; }

public void MuhMethod() {
  Console.WriteLine(MuhProp + MuhOtherProp);
}

This annoys me, I don’t like having to set properties before I call a method I would prefer the method signature to contain all of the data needed to execute the method.


public void MuhMethod(string muhProp, string MyOtherProp)

In fact, if you can use defaults use them, or use overloads.

public void MuhMethod(string muhProp, string MyOtherProp = "BallZacks")

public void MuMethod(string muhProp) 
{
    MuMethod(muhProp, "NutButter");
}