What is the principle of the only responsibility?
In computer programming and design, the principle of the only liability concept that advocates that any class in the program should perform only one function in a larger application. This idea partly promotes some of the ideals of object -oriented programming, such as encapsulation, because the whole class will focus on performing a single responsibility and will not rely little on outer classes. At the same time, it is somewhat antithetic for some of the concepts of early object programming, because the function of a single object is from the data that manipulates the object, which means that it may be necessary to construct many objects in combination to maintain some central data. The principle of the only responsibility is the basis for the design type of design known as design controlled by responsibility.
The example of the principle of only responsibility could take the form of a traditional phone. Some design principles would see a handset and one object that processes both input from the telephone line and the transmission of output from the reprodesUktora. According to one liability model, in which one object should have only one responsibility, the handset would consist of several separate objects that each performed one function, such as receiving input from the telephone line, or just data output via the headphone.
One of the advantages that uses the principle of one responsibility is a very high level of abstraction and modularity. In the example of the headphone, there may be input from the telephone line or the way the signal is issued to the user, changes without affecting neighboring classes if they follow the same connection contract. In addition, the re -usability of certain ingredients can be very high, because each class is fully encapsulated and relies on Very little, if at all, on the surrounding subjects, instead focuses on its one responsibility.
2 This can mean a large number of overhead costs and complicated PRthe design of the design. It can also make it difficult to tune the large program, as one part of the program could consist of thousands of small class files.When the principle of the only responsibility is applied through the design of controlled responsibility, the data and methods used to handle the data are separated for the design purposes. Although this leads to some freedom, encapsulation and modularity in design, it can also generate a number of medium patterns and patterns that must be used to facilitate a number of classes that try to interact with data at the same time. On the other hand, if the object's data and methods are used to manipulate them in a single object with multiple responsibility, then the code can become heavier as a system scale, change or become more complex.