Skip to content

Instantly share code, notes, and snippets.

@halllo
Created November 20, 2012 21:24
Show Gist options
  • Save halllo/4121251 to your computer and use it in GitHub Desktop.
Save halllo/4121251 to your computer and use it in GitHub Desktop.
What do you think about the reuse of ContactInformation?
class Address { }
class PhoneNumber { }
//Service 1
class ContactInformations
{
public ContactInformation PhoneNumbers()
{
return new ContactInformation
{
PhoneNumbers = new List<PhoneNumber>()
};
}
public ContactInformation Addresses()
{
return new ContactInformation
{
Addresses = new List<Address>()
};
}
}
class ContactInformation
{
public List<Address> Addresses { get; }
public List<PhoneNumber> PhoneNumbers { get; }
}
//Service 2
class Persons
{
public IEnumerable<Person> All()
{
yield return new PersonWithPhone();
yield return new PersonWithAddress();
}
}
class Person
{
public string Name { get; set; }
public virtual void Remember(ContactInformation contactInformation)
{
}
}
class PersonWithAddress : Person
{
public List<Address> Addresses { get; private set; }
public override void Remember(ContactInformation contactInformation)
{
Addresses = contactInformation.Addresses;
}
}
class PersonWithPhone : Person
{
public List<PhoneNumber> PhoneNumbers { get; private set; }
public override void Remember(ContactInformation contactInformation)
{
PhoneNumbers = contactInformation.PhoneNumbers;
}
}
@halllo
Copy link
Author

halllo commented Nov 21, 2012

This is just fictional, illustrating a problem I came across some days ago. There are two services, that are entirly out of my control. One provides basic data for contacts (the Contacts repo) and the other provides communication data (the ContactInformations repo) for those contacts. What I want to have is a way of merging the data into the Person object.

@cessor
Copy link

cessor commented Nov 22, 2012

Can you try to express why you want these things?

@halllo
Copy link
Author

halllo commented Nov 22, 2012

"I want to have a list of people, that I can send information to (e.g. christmas greetings), like in a CRM system. The contacts can have either a phone number or a mail address. Depending on what they have, the operator can call or mail the info. The above classes are to be used for seting up the mentioned list.
There are the two services, that provide the phone numbers and the contact addresses, and I want that data to be in a single list of persons."
Is that what you mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment