Design Pattern - (Fluent Interface|Method Chaining)

Card Puncher Data Processing

About

Same technique that the builder pattern to build an Domain Specific Language in declarative way.

The API is primarily designed to be readable and to flow between methods/functions

Spark script uses heavily this concept to process data.

Method chaining lets you write shorter code (and waste less time fretting over variable names).

Implementation

All methods return the same object (a reference to the data).

Typically, a method returns a reference to the element that it just acted on, but not always. When chaining methods, order matters. The output type of one method has to match the input type expected by the next method in the chain.

Example

Non Fluent

Order o1 = new Order();
customer.addOrder(o1);
OrderLine line1 = new OrderLine(6, Product.find("TAL"));
o1.addLine(line1);
OrderLine line2 = new OrderLine(5, Product.find("HPK"));
o1.addLine(line2);
OrderLine line3 = new OrderLine(3, Product.find("LGV"));
o1.addLine(line3);
line2.setSkippable(true);
o1.setRush(true);

Fluent

customer.newOrder()
.with(6, "TAL")
.with(5, "HPK").skippable()
.with(3, "LGV")
.priorityRush();

Documentation / Reference





Discover More
Model Funny
(Function | Operator | Map | Mapping | Transformation | Method | Rule | Task | Subroutine)

Section computable function. A function is a callable unit that may be called: a procedure, a subrontine a routine, a method (belong to an objectmacrocomputablalgorithreusable blocargumentdevelopment...
Card Puncher Data Processing
D3 - Getting Started

Whether you’re building a static chart or a dynamic one with fluid transitions and object constancy, your code remains roughly the same. See also: The...
Card Puncher Data Processing
D3 - Operator

Operators act on selections, modifying content. Operator values are specified either as constants or functions; the latter (the functions) are evaluated for each element. (The functions are evaluated...
Card Puncher Data Processing
Design Pattern - (Object) Builder

The intent of the Builder design pattern is to separate the construction of a complex object from its representation. Same idea than a Instead of using numerous constructors, the builder pattern uses...
Relational Data Model
Functional Programming - Algebraic Data Type

An algebraic data type (Algebraic_data_type) is a data type that is the inputand the output of its own operations. An algebraic structure can be composed before being executed. This is a composite...
Java Conceptuel Diagram
Java - Functional Interface

in Java. A functional interface is is a interface that contains only one abstract method. The interface is so simple that java defines several standard (built-in) functional interfaces Functional...
Card Puncher Data Processing
ReactiveX

is Functional_reactive_programmingFunctional reactive programming library (implemented in several languages) It composes asynchronous and event-based programs using observable asynchronous sequences...



Share this page:
Follow us:
Task Runner