GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java-design-patterns/fluentinterface/README.md at master · wangwch/java-design-patterns

Expand file tree

/

README.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
44 lines (33 loc) · 1.61 KB
/

README.md

Copy path

File metadata and controls

44 lines (33 loc) · 1.61 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions
layout pattern
title Fluent Interface
folder fluentinterface
permalink /patterns/fluentinterface/
categories Other
tags
Java
Difficulty-Intermediate
Functional

Intent

A fluent interface provides an easy-readable, flowing interface, that often mimics a domain specific language. Using this pattern results in code that can be read nearly as human language.

Implementation

A fluent interface can be implemented using any of

  • Method Chaining - calling a method returns some object on which further methods can be called.
  • Static Factory Methods and Imports
  • Named parameters - can be simulated in Java using static factory methods.

Fluent Interface

Applicability

Use the Fluent Interface pattern when

  • you provide an API that would benefit from a DSL-like usage
  • you have objects that are difficult to configure or use

Real world examples

  • Java 8 Stream API
  • Google Guava FluentInterable
  • JOOQ
  • Mockito
  • Java Hamcrest

Credits

  • Fluent Interface - Martin Fowler
  • Evolutionary architecture and emergent design: Fluent interfaces - Neal Ford
  • Internal DSL
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.