Skip to content
Advertisement

How do I connect methods with dots? – Refactoring

I am trying to refactor my code. But I dont know how to do what I want to do. I dont know how it’s called so I dont find it with google. My Code:

JavaScript

I want to refactor everything so the final version looks like this:

JavaScript

or like this:

JavaScript

So the “If(from).IsMultipleOf(3)” shall return true/false and if its true it shall execute the print() function. But I dont know how to do it with the dots (“.”).

Could someone please tell me the right term to google for or show me an example?

-Thanks already in advance!

Advertisement

Answer

You need look for Fluent Api Pattern and Builder Pattern

Simple example

JavaScript

using our simple class

JavaScript
Advertisement