Design: Single Responsibility Principle (SRL)

September 18, 2008

Every object in your system should have a single responibility, and all the object’s services should be focused on carrying out the single responsibility.

This is a simple test that can help to understood if an object violates the SRP.

For each method in your class write the ‘test phrase’:

The class_name method_name itself.

If exist a phrase that has no sense, probably your object is non SRP compliant and you need to refactor your design.

Advertisement

2 Responses to “Design: Single Responsibility Principle (SRL)”

  1. Il senso del codice quando letto con gli occhi del linguaggio naturale dovrebbe essere evidente, se non sempre perlomeno molto spesso. Una disciplina, chiamata Domain Driven Design, si occupa di questo aspetto del design software.
    Dopo le letture degli scorsi anni e le prime scaramucce in pubblico (http://www.sviluppoagile.it/extreme-programming-e-domain-driven-design) terrĂ² un talk su questo argomento al prossimo International PHPCon a Roma. Se ti capita… :)

    Ciao!

  2. wptesto said

    Se riesco vengo di sicuro a sentire…
    Mi sto avvicinando ad Agile (in particolare XP) e la cosa mi iteressa molto…

    Altrimenti ci vediamo all’ AgileCamp2009(http://barcamp.org/AgileCamp2009) :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.