This file contains hidden or 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
| object Wiring { | |
| val recommendAFriend = useCases.RecommendAFriend( | |
| ValidateNewAccount.apply, FindUser.apply, CreateFriend.apply, | |
| PromoteToGoldStatus.apply | |
| ) | |
| } |
This file contains hidden or 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
| object RecommendAFriend { | |
| type RecommendAFriendResult = Either[RecommendAFriendError, Seq[ReferralOutcome]] | |
| type RecommendAFriend = (UserId, NewAccountDetails) => Future[Either[RecommendAFriendError, Seq[ReferralOutcome]]] | |
| type ValidateNewAccount = NewAccountDetails => Option[RecommendAFriendError] | |
| type FindUser = UserId => Future[Option[User]] | |
| type CreateFriend = NewAccountDetails => Future[User] | |
| def apply(v: ValidateNewAccount, f: FindUser, c: CreateFriend, p: ReferralPolicy) | |
| (u: UserId, n: NewAccountDetails): Future[RecommendAFriendResult] = | |
| v(n) map { err } getOrElse { f(u) flatMap { |
This file contains hidden or 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
| object RecommendAFriend{ | |
| type Validate = NewAccountDetails => Unit | |
| type FindCustomer = String => Option[User] | |
| type CreateCustomer = NewAccountDetails => User | |
| type ReferralPolicy = NewAccountDetails => User | |
| def apply(validate: Validate, findCustomer: FindCustomer, createCustomer: CreateCustomer, | |
| referralPolicy: ReferralPolicy) | |
| (referrerId: Int, friendsAccountDetails: NewAcccountDetails) = { | |
| ... |
This file contains hidden or 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
| object RecommendAFriend{ | |
| def apply(validate: NewAccountDetails => Unit, findCustomer: String => Option[User], | |
| createCustomer: NewAccountDetails => User, referralPolicy: (User, User) => Future[Unit]) | |
| (referrerId: Int, friendsAccountDetails: NewAcccountDetails) = { | |
| validate(friendsAccountDetails) | |
| val user = findCustomer(referrerId); | |
| val friend = createCustomer(friendsAccountDetails) | |
| referralPolicy(user, friend) | |
| } |
This file contains hidden or 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
| var referrer = customerDirectory.Find(referrerId); | |
| var friend = customerDirectory.Add(friendsAccountDetails); | |
| referralPolicy.Apply(referrer, friend); |
This file contains hidden or 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
| // construct | |
| val recommendAFriend = RecommendAFriend(validator, customers, policy) | |
| // invoke | |
| recomendAFriend(referrerId, accountDetails) |
This file contains hidden or 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
| object RecommendAFriend { | |
| def apply(validator: NewAccountValidator, customers: CustomerDirectory, policy: ReferralPolicy) | |
| (referrerId: Int, friendsAccountDetails: NewAccountDetails) = | |
| ... | |
| } |
This file contains hidden or 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
| RecommendAFriend(customers, policy, referrerId, friendsAccountDetails) |
This file contains hidden or 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
| object RecommendAFriend { | |
| def apply(customers: CustomerDirectory, policy: ReferralPolicy, referrerId: Int, friendsAccountDetails: NewAccountDetails) = | |
| ... | |
| } |
This file contains hidden or 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
| public class RecommendAFriendService | |
| { | |
| private INewAccountValidator validator; | |
| private ICustomerDirectory customerDirectory; | |
| private IReferralPolicy referralPolicy; | |
| public RecommendAFriendService(ICustomerDirectory customerDirectory, IReferralPolicy referralPolicy, | |
| INewAccountValidator validator) | |
| { | |
| this.validator = validator; |