Encapsulation (original) (raw)

Given a class, the sum of its members complexity should be less than the sum of its parts in isolation.

Suppose there is a Customer entity like this:

public class Customer { public Guid Id { get; set; } public string Name { get; set; } public string SSN { get; set; } public bool Active { get; set; } public string ActivatedBy { get; set; } }

The complexity of the previous class is the same if there were variables like the following:

Guid Id;
string Name;
string SSN;
bool Active;
string ActivatedBy;

Classes that are similar to a bag of data leaks unnecessary complexity. Consider reducing the complexity with something like:

public class Customer { public Guid Id { get; protected set; } public string Name { get; protected set; } public string SSN { get; protected set; } public bool Active { get; protected set; } public string ActivatedBy { get; protected set; } }

Add a custom footer