Questions tagged [fluent-interface]

Refers to a practice of coding object-oriented APIs with the aim of improving readability of the interface, normally implemented using method chaining.

Filter by
Sorted by
Tagged with
7
votes
3answers
809 views

Fluent Validation of Objects

Inspired by this question by t3chb0t and as an elaboration of my own answer, I have written the following solution. My goal was to reduce complexity both in implementation and use. Eventually - I have ...
0
votes
1answer
104 views

Chaining ConstrainableSet<T> [closed]

Based on feedback on my previous question, I made many small adjustments to the code, added more APIs and tried to follow through with delivering on the excellent advice I have received in regards to ...
4
votes
1answer
96 views

Constraining a property setter fluently

The below code is aimed at providing you the most amount of control and flexibility with control which value gets set to a property. I Introduce to you, the ...
7
votes
3answers
200 views

Fluent API for creating random integer arrays in Java

Now I have this fluent API for creating random integer arrays. I can say that I want an array of particular length, having a particular minimum/maximum values and using a particular (or default) ...
0
votes
1answer
60 views

Recursive fluent builder

Problem statement I have entities whose relations form a graph. As an example, let's imagine Users and Groups. Each user has a <...
0
votes
1answer
80 views

Fluent interface for Logger

I was trying to wrap a Logback logger in order to provide some handy methods and already defined default keys of the logged json output and I came up with something like this. Do you spot any ...
3
votes
1answer
90 views

Simple fluent library to validate text content

Before I can perform a more or less complex mappings, treatments in business objects and saving results in databases, I often need to validate contents from flat text files or excel files All the ...
2
votes
1answer
71 views

Switch-like functionality for non-switchable types in Java

Intro This class emulates a switch statement, in order to include non-switchable types (POJOs) have the same switch statement executable for different values be ...
1
vote
1answer
82 views

Wrapper for a sales API, with a fluent interface

I've created a simple API wrapper that I intend a few developers to utilize. I decided to follow an Fluent Interface methodology, similar to this. ...
3
votes
0answers
136 views

Extendable REST-Client - follow-up

My previous RestClient wasn't disposing a lot of resources. I've fixed it (hopefully without introducing new issues) and because a few new patterns emerged I did a ...
3
votes
1answer
80 views
2
votes
2answers
176 views

API with revealing module pattern in Javascript

I'm working on a project where I want to create a API that can be used to do some mathmatical calculations. Here are the important aspects: I used the revealing module pattern I added method ...
6
votes
1answer
563 views

Pathfinding library in C++ with fluent API

Introduction I have this C++ pathfinding library. My primary requirement is that a client programmer may couple his/her own graph representation and the library will work with that representation. ...
4
votes
0answers
112 views

Instantiating an animal using fluent classes with inheritance

I've spent a couple of weeks implementing a simple text editor. The entire program uses only immutable objects and a functional, fluid programming style. After reading about ways to implement Fluent ...
2
votes
0answers
593 views

JObject Pattern Matching: Merging partial WEB API JSON payload

This library [GitHub] helps merging partial WEB API JSON payload with existing prepopulated DTO objects. Let's say that JSON is represented by JObject from JSON.NET package. Naïve implementation ...
5
votes
3answers
525 views

Pizza builder with fluent interface

I make my original program more interesting and try to make the builder API more easier to read: Now it's a static method of Builder: Pizza.Builder.recipeBuild(...) ,who bake the pizza with your ...
3
votes
2answers
207 views

Pizza maker with Bloch builder

I tried to implement the builder pattern of GoF. After searching for almost every related posts/examples on the Internet, I'm still confused. But I found that there are two kinds of patterns, which ...
16
votes
4answers
22k views

Simple builder pattern implementation for building immutable objects

This is a builder pattern implementation to build immutable Person objects: Person class ...
2
votes
3answers
3k views

Methods to create C# dictionaries, with static keys/values, in fluent notation

I created these little utility methods to build fluent C# dictionaries. The value declarations shall be quick to write and easy to comprehend when somebody views the code. Usage conditions are as ...
10
votes
3answers
3k views

Initializing immutable objects with a nested builder

I need to initialize several parameters of an object but I also wanted to make it immutable. At the same time I don't want the constructor to take all several parameters because some of them are ...
2
votes
0answers
310 views

PHPSpec, testing code that uses fluent mock

I've just completed writing a spec for a Doctrine2 repository. The repo contains only one method so far, the spec for which takes in an OAuth Identity token object (that contains an ID that matches up ...
0
votes
2answers
58 views

Hibernate MassIndexer using chained invocation for building a batch job

I've a class called MassIndexer.java (on GitHub) and it uses chained invocation for building a batch job. Each method assigns a property of this job and finally the ...
7
votes
1answer
143 views

HTML-rendering framework for emails

Sometimes I need to auto-generate html-emails. To make this task a little bit easier I created a simple framework that takes care of rendering HTML. Because I'm mainly interested in generating HTML ...
0
votes
1answer
162 views

Fluent interface builder

I'm working on a fluent interface builder that takes: an array of strings, each of which becomes a key to an object that is a function that follows the fluent interface pattern a terminator function ...
9
votes
1answer
1k views

Database abstraction layer for multiple providers

There's been a lot of questions lately about database provider and repository design especially without entity framework or alike. I thought I try myself to create a reusable framework for this kind ...
6
votes
3answers
95 views

Table printing code using a fluent interface

Let's say you want to display something like: One Two Three Four 1 2 3 4 And since you hate the idea of predefining the widths of the columns you ...
3
votes
0answers
56 views

Easily add Accessibility to your app as an afterthought. Yes, as an afterthought

Accessible apps allow more users to use your app; however, it is usually an afterthought for developers, and it makes your XML layout files messy whether Accessibility was a forethought or ...
3
votes
1answer
103 views

Guided object builder

Sometimes when designing a fluent-api it's important to build an object in a specific way/sequence. I tried to create such a guided builder and came-up with this: ...
1
vote
0answers
127 views

Fluent method arguments validation

I've put together a small fluent utility class for argument validation. Part of the code looks as follows: ...
5
votes
2answers
194 views

Find attribute on class property

Since reading Robert Martin's book "Clean Code" I have been inspired to revisit and refactor some of my code to break it down into succinct methods and small specialised classes. Given the need to ...
3
votes
1answer
844 views

Css builder and parser

As part of a larger project I've created recently a simple CssBuilder and CssParser. It's composed of three classes and can ...
5
votes
1answer
77 views

Attempting a fluent API for creating random int arrays

I have attempted doing a fluent API for creating random int arrays, and the following is what I came up with: fluent_arrays.h: ...
8
votes
1answer
867 views

Fluent interface for manipulating employee records

I wanted to try experimenting with fluent interface design in the C programming language. That's why I wanted to ask you, Dear Code Review users, comments on the way I have implement this simple ...
1
vote
1answer
247 views

RPG Character with fluent interface

(Follow-up on RPG Character Builder) This implements a fluent interface for RPG game characters. Is this a valid implementation? There are 3 characters: Paladin, <...
7
votes
2answers
441 views

Fluent Interface for a XmlQueryBuilder

In this answer I suggested using a fluent interface "builder" to replace all the hard-coded, repetitive and quite error-prone inline XML string concatenations. This code might need a bit of tweaking ...
10
votes
6answers
3k views

Fluent interface and polymorphism for building a scene with shapes

I would like to improve the interfaces of some polymorphic classes going from positional to named parameters and I came up with the fluent interface. The following is the most clean, compact and ...
7
votes
1answer
3k views

Fluent Repository/QueryBuilder

I've been toying around making my repositories a bit more fluent for a while. I was ending up with crazy long method names when I had to query on multiple conditions. So I've been working on a way to ...