![]() ![]() MySqlConnection connection = new MySqlConnection("database. The single-responsibility principle (SRP) is a computer programming principle that states that A module should be responsible to one, and only one, actor. ![]() If an order is correctly formed, this module saves it in a database and sends an email to confirm the order: the impact on other objects.Īdditionally, such code is much easier to test, because your tests are covering one piece of functionality in isolation from all others. In other words, we will be able to make changes and not be afraid of the consequences, i.e. Such classes will always be easy to modify if necessary, because it is clear what the class is and is not responsible for. All of a class's services are aimed at supporting this responsibility. Single Responsibility Principle (SRP)This principle states that there should never be more than one reason to change a class.Įach object has one responsibility, which is fully encapsulated in the class. The principles were expressed by Robert Martin in the early 2000s, and then the abbreviation was introduced later by Michael Feathers. Class Person is responsible for holding person related data, it also holds has a function Format which outputs this person data to a given format. SOLID principles in JavaSOLID is an acronym formed from the capital letters of the first five principles of OOP and class design. A class should only have only one reason to change. In Java, these are the so-called SOLID principles, and we're going to talk about them. To understand whether a class is properly written, you can check how it measures up to "quality standards". Poorly written classes can eventually cause problems. Classes are the building blocks of applications. ![]()
0 Comments
Leave a Reply. |