Why is this one of the hardest things for software architects to get right , yet it is the simplest?
Encapsulation
Putting Service layers in place to hide the implementation of the Domain is one of the easiest ways to make a solution scalable. Example in (Model View Controller)MVC the controller looks after the page , but does not expose any detail implementation. There are countless more examples such as Service Layer , Data Gateway and Facade to name but a few.
Interface(Contracts)
IInterface was one of the most interesting discoveries I made soon after my first encounter with OO principles. Lets define a contract and make everyone adhere to it. What could be simpler, Web UI , Windows UI Web Service API and even when my application provides a service to another application. The contract sets the contract.
Loose Coupling
Can you remove one component of your solution and replace it with another without major rework. If you cannot change the Database provider from MS SQL to say MY SQL, you have not done it properly. There might be no requirement for this , but when you are creating a product and have to consider licensing this might make a lot of sense.
public
class PersonDataGatewayMSSQL : IPersonDataGateway
{
//do some stuff in here for MS SQL
}
public class PersonDataGatewayMYSQL : IPersonDataGateway
{
//do some stuff in here for MY SQL
}
public interface IPersonDataGateway
{
public IPerson Create(IPerson person);
public IPerson Read(IPerson person);
public IPerson Update(IPerson person);
public IPerson Delete(IPerson person);
}
All in one go, now that was not too hard !