Last active
December 24, 2023 22:50
-
-
Save mcsee/91a2d630101ba6137f64195e76c1b266 to your computer and use it in GitHub Desktop.
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
<? | |
final class SocialNetworkProfile { | |
private $userName; | |
private $friends; // friends is a reference to a large collection | |
private $feed; // feed references the whole user feed | |
public function __construct($userName, $friends, UserFeed $feed) { | |
$this->assertUsernameIsValid($userName); | |
$this->assertNoFriendDuplicates($friends); | |
$this->userName = $userName; | |
$this->friends = $friends; | |
$this->feed = $feed; | |
$this->assertNoFriendOfMyself($friends); | |
} | |
// Lots of protocol | |
} | |
// If you need to transfer to an external system you need | |
// to duplicate (and maintain) the structure | |
final class SocialNetworkProfileDTO { | |
private $userName; // duplicated to be synchronized | |
private $friends; // duplicated to be synchronized | |
private $feed; // duplicated to be synchronized | |
public function __construct() { | |
// Empty constructor without validations | |
} | |
// No protocol, just serializers | |
} | |
// If you need to transfer to an external system you create an anemic DTO | |
$janesProfileToTransfer = new SocialNetworkProfileDTO(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment