Last active
February 18, 2018 18:23
-
-
Save nicolopignatelli/a2996522f39e23ecf3cbd78f24a7870c 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
package com.mywonderfulbnb.bnb.definition | |
final class Bnb { | |
private BnbId bnbId; | |
private OwnerId ownerId; | |
private Name name; | |
public Bnb(BnbId bnbId, OwnerId ownerId, Name name) { | |
this.bnbId = bnbId; | |
this.ownerId = ownerId; | |
this.name = name; | |
} | |
} |
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
package com.mywonderfulbnb.bnb.definition | |
interface Bnbs { | |
void save(Bnb bnb); | |
} |
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
package com.mywonderfulbnb.bnb.definition | |
final class Service { | |
private Bnbs Bnbs; | |
private ActivatedOwners activatedOwners; | |
public Service(Bnbs bnbs, ActivatedOwners activatedOwners) { | |
this.bnbs = bnbs; | |
this.activatedOwners = activatedOwners; | |
} | |
public addBnb(UUID ownerUuid, UUID bnbUuid, String nameStr) { | |
ownerId = new OwnerId(ownerUuid); | |
bnbId = new BnbId(bnbUuid); | |
name = new Name(nameStr); | |
assertOwnerIsActivated(ownerId); | |
bnb = new Bnb(bnbUuid, ownerId, name); | |
this.bnbs.save(bnb); | |
} | |
private assertOwnerIsActivated(OwnerId ownerId) { | |
itExists = activatedOwners.existsOneWithId(ownerId); | |
if (!itExists) { | |
throw new ActivatedOwnerNotFound(ownerId); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment