0

in jQuery we often do this:

$('#el1').css('margin-left','5px').attr('title','test title').removeClass('class1'); 

in Java StringBuilder, same as above:</p>

StringBuilder builder  = new StringBuilder();  
builder.append("str1").insert(0, 'A').deleteCharAt(2); 

So, what design pattern does this code follow?

4

2 回答 2

5

It's an application of the fluent interface pattern.

于 2013-02-25T03:11:01.413 回答
0

它在 OOP 语言中称为方法链接/命名参数习语。参考http://en.wikipedia.org/wiki/Method_chaining

于 2013-02-25T03:14:44.447 回答