16.1. Responsibilities and Methods

The UML defines a responsibility as “a contract or obligation of a classifier” [OMG01]. Responsibilities are related to the obligations of an object in terms of its behavior. Basically, these responsibilities are of the following two types:

  • knowing

  • doing

Doing responsibilities of an object include:

  • doing something itself, such as creating an object or doing a calculation

  • initiating action in other objects

  • controlling and coordinating activities in other objects

Knowing responsibilities of an object include:

  • knowing about private encapsulated data

  • knowing about related objects

  • knowing about things it can derive or calculate

Responsibilities are assigned to classes of objects during object design. For example, I may declare that “a Sale is responsible for creating SalesLineItems” (a doing), or “a Sale is responsible for knowing its total” (a knowing). Relevant responsibilities related to “knowing” are often inferable from the domain model, because of the attributes and associations it illustrates.

The translation of responsibilities into classes and methods is influenced by the granularity of the responsibility. The responsibility to “provide access to relational databases” may involve dozens of classes and hundreds of methods, packaged in a subsystem. By contrast, the responsibility to “create a Sale” may involve only one or few methods.

A responsibility is not the same thing as a method, but methods are implemented to fulfill responsibilities. Responsibilities are implemented using methods that either act alone or collaborate with other methods and objects. For example, the Sale class might define one or more methods to know its total; say, a method named getTotal. To fulfill that responsibility, the Sale may collaborate with other objects, such as sending a getSubtotal message to each SalesLineItem object asking for its subtotal.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.200.108