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;
}
}
@cessor
Copy link

cessor commented Nov 21, 2012

I feel that "Additional" is a weasel word. It does not say why it is important to define an appointment count. Clearly, appointments seem to be important to what you are doing, so why not introduce an Appointment class for it? I might have only limited insight, but it does not feel right. AppointmentCount is a big weasel, since counts are nothing anybody ever cares about. A count is something that you generate from a database or by calculation, but why is it important for the address?

Is this just a general example, or are you really trying to shoehorn this into your application?

I do not mean to offend your code (or you), I am trying to express my feelings towards it - I clearly do not understand enough about what you are trying to accomplish in order to give a qualified opinion, yet from an emotional, weasel wordy perspective I can give you hint's on where I feel your problem may be.

@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