I've seen code like the following before, which results in a sort of "extension access method" being added to an object. The extension method will appear in intellisense as only one method, but when selected, intellisense will appear with all the methods defined in the "manager" class. It seems like a nice way of organizing a set of similar functionality and decluttering the main intellisense of the primary object.
So, I'm wondering if this technique has some sort of commonly used name, and also whether it's considered a code smell (beyond the general problem of the primary object taking on too much responsibility and getting too large).
public class StringManager
{
public StringManager(String value)
{
Value = value;
}
private String Value { get; set; }
public int GetTwiceLength()
{
return Value.Length * 2;
}
public decimal GetHalfLength()
{
return Value.Length / 2;
}
}
public static class StringExtensions
{
public static StringManager Operations(this String value)
{
return new StringManager(value);
}
}
the above code would be used like so:
var myString = "the string";
var twiceLength= myString.Operations().GetTwiceLength();
Apologies for the silly functionality. This was borrowed from an example on SO where the technique was actually recommended, modified to protect the potentially guilty.