-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hack][builder pattern] Add issue description for PULSE_UNFINISHED_BU…
…ILDER Summary: Add issue description for PULSE_UNFINISHED_BUILDER Reviewed By: davidpichardie Differential Revision: D65419581 Privacy Context Container: L1208441 fbshipit-source-id: f2159cbf64c599ac5dadd591240a52868df0d3f0
- Loading branch information
1 parent
9ac3f7a
commit 325b99c
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Classes adhering to builder pattern are usually expected to call a finalizer function at some point to produce final result based on values that were passed to a builder itself. If finalizer function hasn't been called then builder's data won't be consumed in any meaningful way and will just be discarded. | ||
|
||
```hack | ||
class MyBuilder { | ||
private int $a = 0; | ||
private int $b = 0; | ||
public function setA(int $a): MyBuilder { | ||
$this->a = $a; | ||
return $this; | ||
} | ||
public function setB(int $b): MyBuilder { | ||
$this->b = $b; | ||
return $this; | ||
} | ||
public function saveX(): Awaitable<void> { | ||
// typically do something involving IO | ||
} | ||
} | ||
class BuilderTester { | ||
public static function builderUserOK(): void { | ||
$b = new MyBuilder(0); | ||
$b->setA(42)->setB(97)->saveX(); | ||
} | ||
public static function builderUserBad(): void { | ||
$b = new MyBuilder(0); | ||
$b->setA(42)->setB(97); // ERROR: saveX hasn't been called so the builder's data is discarded | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters