Reputation: 759
I have two entities Publisher and ReferralOffer. An offer is active for only period of time say 2 months. Publisher who bring another person as Refferal gets money which described for that offer. One publisher can bring as many person as he can for a particular offer. After some period that offer expires and new one is generated.
1 ) Now the question is Publisher is my root aggregate, but is refferaloffer is part of Publisher aggregate. or refferaloffer is separate aggregate.
2) Is refferaloffer is value object.
3) how do i create class where refferedTo And refeeredBy can be maintain.
Upvotes: 0
Views: 116
Reputation: 47647
I read wiki article about referral marketing, but that's not enough for me to understand Your business.
Will try to reflect some ideas in code.
Keep in mind - I have little knowledge of business domain.
Omitting/ignoring huge amount of details (e.g. technical difficulties that might arise or even domain related things like when referral becomes a publisher).
But hopefully - that might give You some ideas.
public class Publisher:Root{}
/*
I believe it's a root, because multiple publishers can
bring referrals to one particular referral offer
it could be modeled as entity if offers were given for
publishers individually
it's certainly not a value object, because we care about identity
of particular offer disregarding it's state.
I'm ignoring possibility that there might be various incentives
with common structure/behavior
*/
public class ReferralOffer:Root{
public bool IsActive(){
return _startedOn.AddMonths(-_lengthInMonths)>DateTime.Now;
}
public void BringReferral(string referralName, Publisher boughtBy){
if (IsActive()) _referrals.Add(new Referral(referralName,boughtBy));
}
private List<Referral> _referrals;
public void SendBucksToLuckyBastards(IMoneyTransferService mts){
if (!IsActive()&&!_awardsSent){
_referrals.SelectMany(r=>r.BoughtBy)
.ForEach(p=>mts.SendToPublisher(p,_award));
_awardsSent=true;
}
}
public ReferralOffer(Money award, int lengthInMonths){
_award=award;
_lengthInMonths=lengthInMonths;
_startedOn=DateTime.Now;
}
//assuming it's amount for each referral and not total
private Money _award;
private int _lengthInMonths;
private DateTime _startedOn;
private bool _awardsSent;
}
/*
referral - person who is bought by publisher and who eventually
might become a publisher
if referral automatically becomes a publisher - likely this should
be modeled otherwise
entity, because it makes no sense w/o referral offer
*/
public class Referral:Entity{
public Publisher BoughtBy{get; private set;}
public string Name{get; private set;}
//internal, because only offer constructs them
internal Referral(string name,Publisher boughtBy){
BoughtBy=boughtBy;
Name=name;
}
}
var me=publisherRepository.ByFullName("Arnis Lapsa");
var offer=new ReferralOffer(200,2);
offer.BringReferral(me, "kamal");
//two months later
offer.SendBucksToLuckyBastards(moneyTransferService);
Keep in mind - this code is just to assist You. It's far from good.
Try to understand code thoroughly and see implications every line of code makes.
P.s. criticism is welcome as usual
Upvotes: 1