method-chaining

PHP method chaining benefits?

Still on the PHP-OOP training wheels, this question may belong on failblog.org. =) What are the benefits of method chaining in PHP? I'm not sure if this is important, but I'll be calling my method statically. e.g. $foo = Bar::get('sysop')->set('admin')->render(); From what I've read, any method which returns $this is allowed to be c...

Method chaining with value objects

is it acceptable/good-practice to use the method chaining pattern on value objects (like, returning a new object instead of this)? are there cases out there where this solution is implemented ? I cannot think of any drawbacks, but I'd like to hear your point. ...

Does anyone design api or library code in this way?

I was reading up some things about how to design a library or API well, and stumbled across Joshua Bloch's great talk at Google Tech Talks. Now although I am nowhere near a professional API developer, I think programming a bunch of classes/functions is a similar, although much scaled-down version of the same thing - clear-cut separation ...

Method chaining and the finishing problem

Hi, are there any approaches, given a statement like the following First().Second(); to know from within First() whether/when Second() has executed? Reference: http://martinfowler.com/dslwip/MethodChaining.html ...

PHP: How to chain method on a newly created object?

I would like to know whether there's a way to chain methods on a newly created object in PHP? Something like: class Foo { public function xyz() { ... return $this; } } $my_foo = new Foo()->xyz(); Anyone know of a way to achieve this? ...

MooTools Chaining

I don't think a function/method should ever return voidinstead, it should return this. That's why I was surprised to find out that this doesn't work: $('buttonContainer').getElement('input').set('value', this.get('value') + ' '); What the code is suppose to do is find an <input> that is a child of the element with id attribute value ...

How do chained functions get executed in JQuery?

When a function is chained in JQuery, what is the order of operations? Example 1 $(selector).fun1(val,{fun2(){ }} Example 2 $(selecter).fun1().fun2().fun3() ...

Break method chaining in php

Hi I am using method chaining for my class structure. So my problem is that , how could i break my chain when error occurred in some function. Below is my code: <?php class demo { public __construct() { $this->a='a'; $this->b='b'; $this->error = false; } p...

Fluent API and Method-Chaining Style Usage

When programming against a fluent API or just using method-chaining, I've seen the style mostly like this: var obj = objectFactory.CreateObject() .SetObjectParameter(paramName, value) .SetObjectParameter(paramName, value) .DoSomeTransformation(); What is the reasoning behind putting the dot at the beginning of the line ins...

Detecting end of method chain in PHP?

Hello! I cannot find a simple example about my question above: how can i detect the end of a method chain? I'm just looked Zend_Db_Select for example but this one is too complex for this simple question i think. Is it possible to catch the 'end' of a method chain in PHP? thanks, fabrik ...

Having two $.ajax() calls in one script

Hi. I want to show some progress information of a server side procedure (which in fact is an ffmpeg re-encoding). The best way I though of was to use two different $.ajax() calls on myscript like this: 1) when the form is submitted (which would trigger the re-encoding) one $.ajax() would start the re-encoding like this: $.ajax({ ...

Can a C# method chain be "too long"?

Not in terms of readability, naturally, since you can always arrange the separate methods into separate lines. Rather, is it dangerous, for any reason, to chain an excessively large number of methods together? I use method chaining primarily to save space on declaring individual one-use variables, and traditionally using return methods i...

Naming Suggestions For A Function Providing Chaining In A Different Way

I've coded an experimental function which makes passed objects chainable by using high order functions. It's name is "chain" for now, and here is a usage example; chain("Hello World") (print) // evaluates print function by passing "Hello World" object. (console.log,"Optional","Parameters") (returnfrom) // returns "Hello World" I...

How to do method chaining in Java? o.m1().m2().m3().m4()

I've seen in many Java code notation that after a method we call another, here is an example. Toast.makeText(text).setGravity(Gravity.TOP, 0, 0).setView(layout).show(); As you see after calling makeText on the return we call setGravity and so far How can I do this with my own classes? Do I have to do anything special? ...

Method chaining and exceptions in C#

If I have a method chain like the following: var abc = new ABC(); abc.method1() .method2() .methodThrowsException() .method3() ; assuming I've defined method1(), method2() and method3() as public ABC method1() { return this; } and methodThrowsException() as...

Is it worth to use method chaining in C#?

Having Collection initializers in C# and being allowed to define properties of a class without having to call the constructor, is there any point in using Method Chaining in C#? I can't see any. Maybe I'm missing something here? Thanks ...

how is FLUENT api different from other API

i have come across fluent api while studying DSLs. i have searched alot on FLUENT API..the basic conclusion which i could draw out was that fluent api uses method chaining in order to make the code fluent. but i cannot understand that in object oriented languages we can always create an object and can call the methods related to it. then...

PHP OOP: Method Chaining

I have the following code, <?php class Templater { static $params = array(); public static function assign($name, $value) { self::$params[] = array($name => $value); } public static function draw() { self::$params; } } $test = Templater::assign('key', 'value'); $test = Templater::draw();...

Is there a benefit to storing an object in a variable before calling a method on it?

Example 1: SomeObject someObject = new SomeObject(); if (someObject.Method()) { //do stuff } //someObject is never used again vs Example 2: if (new SomeObject().Method()) { //do stuff } Is there any benefit to using the first method over the second, or vice versa? ...

name for a function that transforms assignment statements to expressions

update Since one effect of these functions is to provide a way to use method chaining on methods that would not normally support it *, I'm considering calling them chain and copychain, respectively. This seems less than ideal though, since the would-be copychain is arguably a more fundamental concept, at least in terms of functional pr...