commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-964) Create fluent APIs where possible
Date Mon, 03 Feb 2014 23:19:06 GMT

    [ https://issues.apache.org/jira/browse/LANG-964?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13890089#comment-13890089
] 

Sebb commented on LANG-964:
---------------------------

An alternative approach might be to encode the escaping type as an extra parameter.
For example:

{code}
StringEscaping.escape(String, Escaping.HTML_3)
StringEscaping.escape(String, Escaping.HTML_4)
StringEscaping.escape(String, Escaping.XML)
{code}

This avoids the need to create intermediate objects whilst alos avoiding the creation of new
methods.

> Create fluent APIs where possible
> ---------------------------------
>
>                 Key: LANG-964
>                 URL: https://issues.apache.org/jira/browse/LANG-964
>             Project: Commons Lang
>          Issue Type: Task
>          Components: General
>            Reporter: Benedikt Ritter
>             Fix For: 4.0
>
>
> A lot of commons-lang is design in an old fashioned way using static util methods. The
problem of this design is, that it encodes a language into method names leading to lots of
variations of the same method in one class. For example StringUtils has over 180 methods,
9 of which a related to splitting.
> Instead of overloading methods and creating method name variations, we should try to
implement fluent APIs. Examples:
> Instead of:
> {code:java}
> StringEscapeUtils.escapeHtml3(String)
> StringEscapeUtils.escapeHtml4(String)
> StringEscapeUtils.escapeXml(String)
> {code}
> the API could look like:
> {code:java}
> StringEscaping.escape(String).with(Escaping.HTML_3)
> StringEscaping.escape(String).with(Escaping.HTML_4)
> StringEscaping.escape(String).with(Escaping.XML)
> {code}
> So no additional methods are necessary when adding new escaping. There are more examples
in commons-lang where the fluent design can be applied. 



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Mime
View raw message