Skip to main content
Added code style around User for consistency with previous edit
Source Link

The Single Responsibility Principle is a good thing to aim for, for many classes. It doesn't always mean that each class only does one thing (though it can), but that it is responsible for a small amount of tightly-related functionality.

That said, the job of some classes is to collect together a number of responsibilities. User may well be one of these, but the individual responsibilities can still be delegated to other classes - e.g. you could always give the userUser an instance of a 'credentials'Credentials class that deals with the password checking.

You almost certainly don't want your database-related functions in User as if you write any tests for User, many of them are likely to have a need to hit the database when they run.

The Single Responsibility Principle is a good thing to aim for, for many classes. It doesn't always mean that each class only does one thing (though it can), but that it is responsible for a small amount of tightly-related functionality.

That said, the job of some classes is to collect together a number of responsibilities. User may well be one of these, but the individual responsibilities can still be delegated to other classes - e.g. you could always give the user an instance of a 'credentials' class that deals with the password checking.

You almost certainly don't want your database-related functions in User as if you write any tests for User, many of them are likely to have a need to hit the database when they run.

The Single Responsibility Principle is a good thing to aim for, for many classes. It doesn't always mean that each class only does one thing (though it can), but that it is responsible for a small amount of tightly-related functionality.

That said, the job of some classes is to collect together a number of responsibilities. User may well be one of these, but the individual responsibilities can still be delegated to other classes - e.g. you could always give User an instance of a Credentials class that deals with the password checking.

You almost certainly don't want your database-related functions in User as if you write any tests for User, many of them are likely to have a need to hit the database when they run.

The Single Responsibility PrincipleSingle Responsibility Principle is a good thing to aim for, for many classes. It doesn't always mean that each class only does one thing (though it can do), but that it is responsible for a small amount of tightly-related functionality.

That said, the job of some clasesclasses isis to collect together a number of responsibilities. UserUser may well be one of these, but the individual responsibilities can still be delegated to other classes - e.g. you could always give the user an instance of a 'credentials' class that dealtdeals with the password checking.

You almost certainly don't want your database-related functions in 'User'User as if you write any tests for UserUser, many of them are likely to have a need to hit the database when they run.

The Single Responsibility Principle is a good thing to aim for for many classes. It doesn't always mean that each class only does one thing (though it can do), but that it is responsible for a small amount of tightly-related functionality.

That said, the job of some clases is to collect together a number of responsibilities. User may well be one of these, but the individual responsibilities can still be delegated to other classes - e.g. you could always give the user an instance of a 'credentials' class that dealt with the password checking.

You almost certainly don't want your database-related functions in 'User' as if you write any tests for User, many of them are likely to have to hit the database when they run.

The Single Responsibility Principle is a good thing to aim for, for many classes. It doesn't always mean that each class only does one thing (though it can), but that it is responsible for a small amount of tightly-related functionality.

That said, the job of some classes is to collect together a number of responsibilities. User may well be one of these, but the individual responsibilities can still be delegated to other classes - e.g. you could always give the user an instance of a 'credentials' class that deals with the password checking.

You almost certainly don't want your database-related functions in User as if you write any tests for User, many of them are likely to have a need to hit the database when they run.

Source Link

The Single Responsibility Principle is a good thing to aim for for many classes. It doesn't always mean that each class only does one thing (though it can do), but that it is responsible for a small amount of tightly-related functionality.

That said, the job of some clases is to collect together a number of responsibilities. User may well be one of these, but the individual responsibilities can still be delegated to other classes - e.g. you could always give the user an instance of a 'credentials' class that dealt with the password checking.

You almost certainly don't want your database-related functions in 'User' as if you write any tests for User, many of them are likely to have to hit the database when they run.