Single Responsibility Principle

All Classes should have a single responsibility (one thing to do) and each responsibility should be entirely encapsulated by a single class.

This principle applies the traditional best practice of keeping Coupling Low and Cohesion High to OO development. High Cohesion; putting together things that logically belong together, means that a change of requirements will typically impact few classes. Low Coupling between Classes means that changes to one class will have minimal impact on another class. Following this approach typically allows classes to be more readily reused.

CRC (Class Responsibility & Collaboration) Cards are a useful aid to establish the responsibilities of each class. When determining the responsibilities of a class, if you are forced to use the word 'AND' when describing the responsibilities of a class then split the responsibilities on the word 'AND'. So if Class Foo does A & B, then make Foo a composition of Classes FooA and FooB.

oo_single_responsibility_principle.txt ยท Last modified: 2009/09/22 13:46 (external edit)