Они в сущности говорят одно и то же в разных словах.
Вы должны написать свой класс, чтобы он зависел от абстрактной идеи (например, интерфейса) вместо конкретной реализации идеи. Это позволяет вам изменять поведение на куски, а не переписывать целые куски кода.
См. Injection Dependancy Injection.
Пример:
public class Chef : IResturauntWorker
{
// This is an example of writing to an interface instead of an
// an implementation. Because the Chef class implements the
// IResturauntWorker interface, the chef can be swapped in with other
// resturaunt workers like bussers or waiters.
public void Chop(Carrot c)
{
// code to chop a carrot
// this is an example of depending on an implementation
// because Carrot is a concrete class, this method can
// only be used with a Carrot
}
public void Chop(IVegetable c)
{
// code to chop a Vegetable
// this is an example of depending on an abstraction
// because IVegetable is a abstraction of an idea
// (a vegetable, in this case), this method can be
// used with any class that implements IVegetable,
// including carrots, celery, onions, etc.
}
}
Этот вопрос будет лучше для программистов.stackexchange.com –