Method chaining is the name:
https://en.wikipedia.org/wiki/Method_chaining
api’s that use are often called fluent. It’s also used in the builder pattern.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In C#, we can use:
objectName.method
className.method
this.method
Please look at the following code, GetManager is a method, IsValid is also a method. Of course, GetManager will return an object. Ultimately, GetManager().IsValid(fileName) is actually an invocation of the ‘objectName.method’ type. But in form, GetManager().IsValid(fileName) is still a ‘method.method’ type of invocation.
My question is: Is there a specific term to define this ‘method.method’ syntax in C#? I want to search for this syntax knowledge based on the specific term.
public class LogAnalyzerUsingFactoryMethod
{
public bool IsValidLogFileName(string fileName)
{
return GetManager().IsValid(fileName);
}
protected virtual IExtensionManager GetManager()
{
return new FileExtensionManager();
}
}
Method chaining is the name:
https://en.wikipedia.org/wiki/Method_chaining
api’s that use are often called fluent. It’s also used in the builder pattern.
Fluent api's are methods that are generally returning this. So you can continue to call methods on the object you started with like for instance is done in builders. Your api is far from fluent.
What you are doing is just plain method call chaining. method1.method2 is confusing because that is not what you do. the result of method1 is an object, in your case a different one than where you began, and method2 is a method on the result object of method 1.
I don 't even think there is a specific name for it. But if your so called 'chain' is too deep, they call it a train wreck and it is a design smell.