Responsibility-driven design
Encyclopedia
Responsibility-driven design is a design technique in Object-oriented programming
. It was proposed by Rebecca Wirfs-Brock
and Brian Wilkerson who defined it as follows:
The client/server model they refer to assumes that a software client and a software server exchange information based on a contract that both parties commit to adhere to. The client may only make the requests specified, the server must answer them. Thus, responsibility-driven design tries to avoid dealing with details, such as the way in which requests are carried out, by instead only specifying the intent of a certain request. The benefit is increased encapsulation, since the specification of the exact way in which a request is carried out is private to the server.
To further the encapsulation of the server, Wirfs-Brock and Wilkerson call for language-features that limit outside influence to the behavior of a class. They demand that visibility of members and function should be finely grained, such as in Eiffel
. Even finer control of the visibility of even classes is available in the Newspeak
programming language.
Responsibility-driven design is in direct contrast with Data-driven design
, which promotes defining the behavior of a class along the data that it holds.
and Responsibility-driven design. The law of Demeter says that messages can be sent only to the following: message argument, instance variable, new objects, global variables. Therefore, sending a message to the result of a previous message send isn't allowed. However, "returned values are part of the client/server contract. There need be no correlation between the structure of an object and the object returned by the message."
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
. It was proposed by Rebecca Wirfs-Brock
Rebecca Wirfs-Brock
Rebecca J. Wirfs-Brock is an author and consultant in object-oriented programming and object-oriented design, the founder of the information technology consulting firm Wirfs-Brock Associates, and inventor of Responsibility-Driven Design, the first behavioral approach to object design.Wirfs-Brock...
and Brian Wilkerson who defined it as follows:
Responsibility-driven design is inspired by the client/server model. It focuses on the contract by asking:
- What actions is this object responsible for?
- What information does this object share?
The client/server model they refer to assumes that a software client and a software server exchange information based on a contract that both parties commit to adhere to. The client may only make the requests specified, the server must answer them. Thus, responsibility-driven design tries to avoid dealing with details, such as the way in which requests are carried out, by instead only specifying the intent of a certain request. The benefit is increased encapsulation, since the specification of the exact way in which a request is carried out is private to the server.
To further the encapsulation of the server, Wirfs-Brock and Wilkerson call for language-features that limit outside influence to the behavior of a class. They demand that visibility of members and function should be finely grained, such as in Eiffel
Eiffel (programming language)
Eiffel is an ISO-standardized, object-oriented programming language designed by Bertrand Meyer and Eiffel Software. The design of the language is closely connected with the Eiffel programming method...
. Even finer control of the visibility of even classes is available in the Newspeak
Newspeak (programming language)
Newspeak is a programming language and platform in the tradition of Smalltalk and Self being developed by a team led by Gilad Bracha. The platform includes an IDE, a GUI library, and standard libraries. Starting in 2006, Cadence Design Systems funded its development and employed the main...
programming language.
Responsibility-driven design is in direct contrast with Data-driven design
Data-driven design
In computer programming, data-driven programming is a programming paradigm in which the program statements describe the data to be matched and the processing required rather than defining a sequence of steps to be taken. Adapting abstract data type design methods to object-oriented programming...
, which promotes defining the behavior of a class along the data that it holds.
Conflict with the law of Demeter
According to Wirfs-Brock and Wilkerson, there's a conflict between the Law of DemeterLaw of Demeter
The Law of Demeter or Principle of Least Knowledge is a design guideline for developing software, particularly object-oriented programs. In its general form, the LoD is a specific case of loose coupling...
and Responsibility-driven design. The law of Demeter says that messages can be sent only to the following: message argument, instance variable, new objects, global variables. Therefore, sending a message to the result of a previous message send isn't allowed. However, "returned values are part of the client/server contract. There need be no correlation between the structure of an object and the object returned by the message."