我有两个实体Publisher和ReferralOffer。优惠仅在一段时间内有效,例如2个月。出版商带来另一个人作为推荐人,得到的钱是为该报价描述的。一个出版商可以为一个特定的报价带来尽可能多的人。经过一段时间后,该报价到期并生成新报价。
1)现在的问题是Publisher是我的根聚合,但is refferaloffer是Publisher聚合的一部分。或者refferaloffer是单独的聚合。
2)是refferaloffer是值对象。
3)如何创建可以维护refferedTo和refeeredBy的类。
发布于 2010-12-14 20:50:48
我在wiki article上读过关于推荐营销的文章,但这还不足以让我了解你们的业务。
将尝试在代码中反映一些想法。
请记住,我对业务领域知之甚少。
省略/忽略大量的细节(例如,可能出现的技术困难,甚至与领域相关的事情,比如什么时候成为发布者)。
但希望-这可能会给你一些想法。
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);请记住,这段代码只是为了帮助你。情况一点也不好。
试着透彻地理解代码,会看到每一行代码的含义。
附注:批评一如既往地受到欢迎
https://stackoverflow.com/questions/4423159
复制相似问题