Shouldn't in the following model an Address be a Value Object? - domain-driven-design

From How are Value Objects stored in the database? :
Assume that a Company and Person both have the same mail Address.
Which of these statements do consider valid?
   1."If I modify Company.Address, I want Person.Address to automatically get those changes"
   2."If I modify Company.Address, it must not affect Person.Address"
If 1 is true, Address should be an Entity
If 2 is true, Address should be a Value Object.
Shouldn't in the above model the mail Address be a Value Object, since even if Company and Person have same mail, this mail still doesn't have a conceptual identity?
In other words, if initially Company and Person share initial.address#gmail.com, but then get new mail new.address#gmail.com, then we can argue that mail address initial.address#gmail.com itself didn't changed, instead Company and Person replaced it by new.address#gmail.com ?
Thus to my understanding a mere fact that Address is shared shouldn't be enough to give it personality (ie identity)?!
Thank you

Yes, your understanding is correct. Address should almost always be a value object, since in most domains, the address is indeed just a value.
The fact that a Company and a Person have the same Address today does not mean that if one changes, the other should change too. If such a relationship exists, it should be modeled through an explicit constraint rather than by making Address an entity.
Eric Evans talks about this in his excellent book on Domain-Driven Design and even provides a specific example where Address might be an entity -- the postal service, whose domain revolves around addresses, and where the identity of individual addresses is important.

Actually, the mail has a conceptual identity. The problem is that you aren't really modeling the e-mail address, but the Contact Information of a Person and/or the Contact Information of a Company.
Continuing with the topic, value object vs identity object is more an implementation decision rather than a "absolute truth".
You could use an immutable value object and when you tell the system "change address a for address b" search for all instances of address A in both person and the company, and update them to point to address b now. (or you could just update a single one of them).
Using a non-value Contact Information object is more powerful.
With:
Contact Information
{
string email;
}
You could actually have both person and company pointing to the same Contact Information object, so when you update one, you update the other too. Or you could have each of them point to a different Contact Information object, so when you update one, you don't modify the other...
BTW: e-mail has conceptual identity, since changing the e-mail address is actually what google did to me last week, when they changed my e-mail address from ending in #googlemail.com to #gmail.com... So if someone had my e-mail for both me and my company, just one update just change both instances, since in that ocassion my e-mail address changed itself... If on the other hand, I start using a different e-mail address, what changes is my contact information... My old e-mail address would still exist and be the same.
My advise is to model everything with identity, unless it's an extremely well object of a domain which you want to optimize an use as a value object for whatever reason (such as numbers, strings, etc...). But remember that it's usually a implementation decision, not something of the domain.

This is a classic case of taking something out of context.
The original question (How are Value Objects stored in the database) wasn't questioning the validity of the model, and my example wasn't to highlight these issues either. My answer was about Persistence vs Entity/VO.
I used the example of Customer, Person, and Address purely so that I could share the same Ubiquitous Language with the OP (I didn't have time to think up a better example).
I would follow casablanca's advice on this one (upvoted)

Related

Similar paradigms as readers-writers prob and producer-consumer prob

for my Operating Systems Networking class, we must come up with a common paradign that is faced when developing operating systems and propose a solution to the paradigm. Some possible topics suggested in class were: Producer/Consumer problem, reader/writer problem and there was a third one, idk the name for it. It was something like this:
Protection of Private Data – When a user has personal or private data he must share with a network in order to get information, but doesn’t want his information to be released.
-If a user must request a server for information and must provide some private data, the user tells his OS to request the information by sending a series or an array of data to the server. Some are actual data and some are fake. The server responds, handling each set of data as a separate request, it then returns the results and the OS picks the right one.
Example:
1) Person A uses his phone which uses his GPS coordinates to locate the closest bank. The OS on the phone knows that if the GPS coordinates were to get out, this could be bad. The phone instead, sends a request to AT&T asking for the closest bank for the following locations: the actual location person A is at, as well as 3 other fake locations. AT&T has no way of telling which location is the true location and which are the fake ones and is therefore forced to treat each one as a separate request. The results are sent back to the phone and the phone uses only the result for the location that is correct.
Another problem one of my friends did last semester was DDoS. I was wondering if you guys new of any other problems,issues or paradigms that are still lurking about.
Thank you for your suggestions.

SSIS Split String address

I have a column which is made up of addresses as show below.
Address
1 Reid Street, Manchester, M1 2DF
12 Borough Road, London, E12,2FH
15 Jones Street, Newcastle, Tyne & Wear, NE1 3DN
etc .. etc....
I am wanting to split this into different columns to import into my SQL database. I have been trying to use Findstring to seperate by the comma but am having trouble when some addresses have more "sections" than others. ANy ideas whats the best way to go about this?
Many THanks
This is a requirements specification problem, not an implementation problem. The more you can afford to assume about the format of the addresses, the more detailed parsing you will be able to do; the other side of the same coin is that the less you will assume about the structure of the address, the fewer incorrect parses you will be blamed for.
It is crucial to determine whether you will only need to process UK postal emails, or whether worldwide addresses may occur.
Based on your examples, certain parts of the address seem to be always present, but please check this resource to determine whether they are really required in all UK email addresses.
If you find a match between the depth of parsing that you need, and the assumptions that you can safely make, you should be able to keep parsing by comma indexes (FINDSTRING); determine some components starting from the left, and some starting from the right of the string; and keep all that remains as an unparsed body.
It may also well happen that you will find that your current task is a mission impossible, especially in connection with international postal addresses. This is why most websites and other data collectors require the entry of postal address in an already parsed form by the user.
Excellent points raised by Hanika. Some of your parsing will depend on what your target destination looks like. As an ignorant yank, based on Hanika's link, I'd think your output would look something like
Addressee
Organisation
BuildingName
BuildingAddress
Locality
PostTown
Postcode
BasicsMet (boolean indicating whether minimum criteria for a good address has been met.)
In the US, just because an address could not be properly CASSed doesn't mean it couldn't be delivered - cip, my grandparent-in-laws live in enough small town that specifying their name and city is sufficient for delivery as local postal officials know who they are. For bulk mailings though, their address would not qualify for the bulk mailing rate and would default to first class mailing. I assume a similar scenario exists for UK mail
The general idea is for each row flowing through, you'll want to do your best to parse the data out into those buckets. The optimal solution for getting it "right" is to change the data entry method to validate and capture data into those discrete buckets. Since optimal never happens, it becomes your task to sort through the dross to find your gold.
Whilst you can write some fantastic expressions with FINDSTRING, I'd advise against it in this case as maintenance alone will drive you mad. Instead, add a Script Transformation and build your parsing logic in .NET (vb or c#). There will then be a cycle of running data through your transformation and having someone eyeball the results. If you find a new scenario, you go back and adjust your business rules. It's ugly, it's iterative and it's prone to producing results that a human wouldn't have.
Alternatives to rolling your address standardisation logic
buy it. Eventually your business needs outpace your ability to cope with constantly changing business rules. There are plenty of vendors out there but I'm only familiar with US based ones
upgrade to SQL Server 2012 to use DQS (Data Quality Services). You'll probably still need to buy a product to build out your knowledge base but you could offload the business rule making task to a domain expert ("Hey you, you make peanuts an hour. Make sure all the addresses coming out of this look like addresses" was how they covered this in the beginning of one of my jobs).

How to prevent duplicates in online anonymous surveys?

I am writing an online survey and I am wondering if there are any good techniques for allowing anonymous people to go to the survey and participate and also prevent duplicates.
I have considered the following, but there are drawbacks from each:
Use cookie in browser
Record IP address
Compare answers for similarities along with either/or the first two methods
Of the techniques I have considered, you either prevent multiple people from using the same device, or make it easy for a user to duplicate survey results. Hopefully someone has an excellent way to prevent this :)
Well I am not sure whether you are thinking of deliberate or accidental duplicates?
if you think people will want to post a load of results to skew the survey, I cannot add anything because any ID-related question you ask can be falsely answered.
if you want people to just give their answers without having to go through a login process, how about asking for their initials plus birthdate (ddmmyyyyfl)- that has a pretty good chance of being unique without really compromising their identities or taking too much time.
Was that what you were after?
Ed
I am currently investigating a similar scenario.
Some of the suggestions I found online are:
You generate a unique URL - which you can send to their email (this email does not have to be stored), and then you add a checksum to the URL to verify it is valid.
Similar to the above mentioned, you provide them with an uniquely generated password, and you validate whether the password has been used before.
The clear limitation is that you require their email, and this is slightly lengthy. However, the email address is not associated with the answer set.
Meaning, you can validate whether an email address has been used to send a URL/Password to. Prevents same email address from being used over and over.
Then when the URL/Password is used, you validate whether that unique reference has been used in an answer set before. (The answer set is associated with the Unique Reference, and not the person's email - ensuring anonymity).
The problem with using email, ID numbers, and Birth Date; is that all of these values can be fabricated.If this approach is used, also do not forget good old CAPTCHA, as a script can be created to run through the combinations and submit answer sets.
I realize this is an old post, but hopefully it helps someone at some point. All of the best.

best way to model the following scenario

I am starting of in the world of DD and am attempting to build a simple enough application. I have a few questions on how I am choosing to model my domain.
My application allows users to order greeting cards.
The user can order any number of cards in one order.
When choosing a card to order they browse the card catalogue. THe card catalogue however is not stored locally, its retrieved from an external system, however every card they have browsed to in their current session will be cached locally in the database for the lifetime of that session in case they wish to add to the order.
When they add a card to the order, it goes on a new order line item. THey then must specify some other details for the order line item, colour, greeting etc...
My question is this:
How do I model the card in my domain. I have Order as an aggregate root, with many order line items. Each order line item will have certain attributes, and a card.
However my card catalogue will also have a card concept which will have the same properties as the card on my order line item.
Am I correct in modelling these cards as 2 seperate entities (CatalogueCard and OrderCard) even though they have the same set of properties?
The same question could be posed also for the address a card must be addressed to(each order line item will have an address) and the billing address for the order. Should these be modelled as completley seperate entities?
Thanks in advance
The fact that you're seeing business entity concepts repeated as you model your domain means that you're probably on the right track. But if you have two objects with the same set of attributes you should definitely just use one. CatalogueCard and OrderCard should be instance names, not class names, except if you expect some change then you can inherit from a base Card class. Same goes for your address class. Just use one address class. The address type should just be another attribute which could be an enum value of the types of addresses your model supports.

How to determine the aggregate root

I have an application in which an Engineer accesses gas wells. He can see a list of wells by choosing any combination of 7 characteristics. The characteristics are company, state, county, basin, branch, field, operator in their respective order. The application starts and I need to retrieve a list of companies. The companies the user sees is based on their security credentials. What would be my aggregate root/domain object which to base my repository. I first thought user, but I never retrieve anything about a user. The combination of those items and a couple of other attributes are collectively called wellheader information. Would that be the aggregate root or domain object for my repository?
Thanks in advance
With a short description like that, it can only be a quess on how your design could be.
As I read it, your are really interested in wells for a given engineer. (is the engineer the user you mention?)
So a first try could be to model the concept of a well as an aggregate root.
So maybe something like this:
ICollection<Well> wells = WellRepository.GetWellsForEngineer(engineerInstance);
Maybe your engineer is associated with a characteristics object.
Either way, you have to associate the engineer with wells in a given company, state and so on to be able to extract which wells the engineer is actualy assigned to.
If this dosen't help you, maybe you could elaborate on your domain.

Resources