Re: How do you handle free-text associations with DDD

Giacomo Tesio <[email protected]>
Newsgroups gmane.comp.programming.domain-driven-design
Message-ID <CAHL7psE4AZNJ0zGbCeBTkAbbvEjYGVUF8em8Bwm0GUS2LPRe2Q@mail.gmail.com>
What do you think about a hierarchy of Invoice (the abstract one, derived
by the others), CustomerInvoice and FreeInvoice?
CustomerInvoice would derive Invoice and use a CustomerIdentifier to relate
to the customer and the FreeInvoice would simple use a string.


Giacomo

On Tue, Mar 12, 2013 at 11:16 AM, codewithcoffee
<[email protected]>wrote:

> **
>
>
>
> Hello All,
>
> I will first present a simple example which I know that I shouldn't talk
> about UI first, but it places the example in a context.
>
> So - imagine two agg. roots: Invoice and Customer. Invoice has an
> association to Customer, but there is also a possibility to define a
> customer for an invoice by simply typing the customer name into the
> "Customer" textbox. I would call this free-text.
>
> There are two possibilities here as I see them:
>
> - have a text property on Invoice in which the customer name is stored
> (I would not go for this at all), and then provide messy code that
> decides what to return when you ask for the Customer.
> - create a new Customer when saving the Invoice, by providing his newly
> typed name since this is the only dependency of the Customer root.
>
> I would always lean for second approach, but take into account that we
> don't want these "free" customers displayed in our "Customers view" for
> example. So, what could you do? Add a property on Customer that would
> distinguish these entries?
>
> I would also presume that since this "feature" is required in the
> domain, we would have requirements like: "User is able to define a Free
> Customer on an Invoice" and an UI requirement like "User should not see
> Free Customers in Customers View".
>
> One option that I see is having inheritence in place here, meaning
> specific entities Customer and FreeCustomer entities, but again I am
> little confused how to model this in DDD way.
> Would FreeCustomer inherit Customer which is agg. root? Would callers of
> interating over all Customers try to cast to FreeCustomer? I generally
> don't like inheritance that much.
>
> This example is completely made up, and I know what there are no
> "concrete" questions here; but I would appreciate any comments about the
> thoughts given here :=)
>
> Best regards, Denis
>
>  
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.