关于实体的聚合问题

发布于 2024-10-07 05:55:39 字数 309 浏览 0 评论 0原文

我有两个实体 Publisher 和 ReferralOffer。优惠仅在一段时间内(例如 2 个月)有效。引入另一个人作为推荐人的发布商将获得该报价所述的资金。一个发布商可以为某一特定报价带来尽可能多的人。一段时间后,该优惠到期并生成新的优惠。

1 )现在的问题是 Publisher 是我的根聚合,但 refferaloffer 是 Publisher 聚合的一部分。或 refferaloffer 是单独汇总的。

2) refferaloffer 是否是价值对象。

3)我如何创建可以维护 refferedTo 和 refeeredBy 的类。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝影如岚 2024-10-14 05:55:39

我阅读了有关推荐营销的wiki 文章,但这还不足以让我了解您的业务。

  1. 您的情况有什么推荐优惠?
  2. 您想解决什么样的问题?您申请的目的?
  3. 推荐优惠发布商是否特定?
  4. 是否可以有多个发布商带人参加一项特定的推荐优惠?

将尝试在代码中反映一些想法。

请记住 - 我对业务领域知之甚少。

省略/忽略大量细节(例如,可能出现的技术困难,甚至是与领域相关的事情,例如当推荐成为发布商时)。

但希望 - 这可能会给你一些想法。

 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);

请记住 - 该代码只是为了帮助您。情况远非如此。

尝试彻底理解代码并了解每行代码的含义

PS一如既往地欢迎批评

I read wiki article about referral marketing, but that's not enough for me to understand Your business.

  1. What's a referral offer in Your case?
  2. What kind of problems You are trying to solve? Aim of Your application?
  3. Is referral offer publisher specific?
  4. Can more than one publisher bring persons for one particular referral offer?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文