This principle states:
An object should be Open for Extensions but Closed for Modifications.
Take a query scenario: The aim is to allow querying classes to query an object without have to change source code on the query class. In other words not having to add new methods for each new query.
This can be done by the Specification Pattern (out of box Dot Net Partterm) in particular the Predicate Delegate Pattern. (definition: Ask an Object if another Object meets a certain criteria)
Using the sample from DNRTV episode.
--------------------------------- Querying Class --------------------------------------
public void Should_find_all_employees_with_a_last_name_beginning_with_B()
{
IEmployeeContactBook book = CreateContactBook();
AddDefaultListOfEmployeesTo(book);
Assert.AreEqual(2,GetCountOf(book.AllContactsMatching(LastNameStartsWithB)));
}
public LastNameStartsWithB(IEmployee employee)
{
return employee.LastName.StartsWith("B");
}
----------------- Query Class ------------------------------------------------------
public IEnumerable
{
foreach (IEmployee contact in contacts)
{
if (match(contact))
{
yield return contact;
}
}
}





