Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e06f063

Browse files
committed
Fluentinterface
1 parent 7faca2a commit e06f063

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

‎Fluentinterface/index.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/**
4+
* Design pattern "Fluent interface" (Structural)
5+
* This is demo code
6+
* See for details: http://maxsite.org/page/php-patterns
7+
* https://en.wikipedia.org/wiki/Fluent_interface
8+
*/
9+
10+
/**
11+
* Any class
12+
*/
13+
class MyName
14+
{
15+
private $FirstName = '';
16+
private $LastName = '';
17+
18+
/**
19+
* return $this
20+
*/
21+
public function __construct()
22+
{
23+
return $this;
24+
}
25+
26+
/**
27+
* return $this
28+
*/
29+
public function setFirstName($FirstName)
30+
{
31+
$this->FirstName = $FirstName;
32+
return $this;
33+
}
34+
35+
/**
36+
* return $this
37+
*/
38+
public function setLastName($LastName)
39+
{
40+
$this->LastName = $LastName;
41+
return $this;
42+
}
43+
44+
/**
45+
* return result
46+
*/
47+
public function getResult()
48+
{
49+
return $this->FirstName . '' . $this->LastName;
50+
}
51+
}
52+
53+
54+
/**
55+
* demo
56+
*/
57+
58+
$fullName = (new MyName())->setFirstName('Don')->setLastName('Joe')->getResult();
59+
60+
echo $fullName; // Don Joe
61+
62+
# end of file

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /