In the code sample below. Would UserId
, Email
, and UserType
be considered "dependencies" with respect to the ChangeEmail
method? would they be considered "collaborators"? Is it a condition for a member to be of a complex type for it to be considered either?
public class User
{
public int UserId { get; private set; }
public string Email { get; private set; }
public UserType Type { get; private set; }
public void ChangeEmail(int userId, string newEmail)
{
object[] data = Database.GetUserById(userId);
UserId = userId;
Email = (string)data[1];
Type = (UserType)data[2];
if (Email == newEmail)
return;
object[] companyData = Database.GetCompany();
string companyDomainName = (string)companyData[0];
int numberOfEmployees = (int)companyData[1];
string emailDomain = newEmail.Split('@')[1];
bool isEmailCorporate = emailDomain == companyDomainName;
UserType newType = isEmailCorporate ? UserType.Employee : UserType.Customer;
if (Type != newType)
{
int delta = newType == UserType.Employee ? 1 : -1;
int newNumber = numberOfEmployees + delta;
Database.SaveCompany(newNumber);
}
Email = newEmail;
Type = newType;
Database.SaveUser(this);
MessageBus.SendEmailChangedMessage(UserId, newEmail);
}
}
public enum UserType
{
Customer = 1,
Employee = 2
}
ChangeEmail
is setting up attributes, but it's not operating through or with them. The method could be rewritten so it doesn't make any reference to the members and it would still compile and work. Basically, the method doesn't depend on any of the members to actually do its job. The only it needs isDatabase
ChangeEmail
, not consumers. Anyways, it doesn't change the observation. The method will work with or without these members because it doesn't use them. Not sure if we can tag instance attributes as "dependencies". I guess it depends on the kind of object. If it's a service, then yes, dependencies are likely collaborators. If it's a POJO ... I don't see it so clear.