Object Design Roles, Responsibilities and Collaborations Flashcards
OO: What is an application?
a set of interacting objects
OO: What is an object?
an implementation of one or more roles. An object embodies a set of roles with a designated set of responsibilities.
“The object has three properties, which makes it a simple, yet powerful model building block. It has state so it can model memory. It has behavior, so that it can model dynamic processes. And it is encapsulated, so that it can hide complexity.”
OO: What is a role?
a set of related responsibilities. A role is a set of responsibilities that can be used interchangeably.
OO: What is a responsibility?
an obligation to perform a task or know information
OO: What is a collaboration?
an interaction of objects or roles (or both)
OO: What is a contract?
an agreement outlining the terms of a collaboration. An object contract describes the conditions under which it guarantees its work and the effects it leaves behind when its work is complete.
OO: What is the difference between an object and a role?
When a role
is always played by the same kind of object, the two are equivalent. But if more than one kind of object can fulfill the
same responsibilities within the community, a role becomes a set of responsibilities that can be fulfilled in different
ways. A role is a slot in the software machinery to be filled with an appropriate object as the program runs.
OO: Why do we use Object Role StereoTypes?
Because our goal is to build consistent and easy-to-use objects, it is advantageous to stereotype objects, ignoring specifics of their behaviors and thinking about them at a higher level. By oversimplifying and characterizing it, we can ponder the nature of an object’s role more easily.
OO: List 6 useful Object Role Stereotypes.
Information holder—knows and provides information
Structurer—maintains relationships between objects and information about those relationships
Service provider—performs work and, in general, offers computing services
Coordinator—reacts to events by delegating tasks to others
Controller—makes decisions and closely directs others’ actions
Interfacer—transforms information and requests between distinct parts of our system
OO: What happens when an object falls into multiple object role stereotypes? How do you decide which one to take?
Some objects are hard to stereotype because they seem to fit into more than one category. They’re fuzzy. How can you choose? You must decide what you want to emphasize. A transmission is a service provider if you emphasize the multiplication of power by the gears. It is an interfacer if you emphasize its connections to the engine and wheels.
Can objects have more than one stereotype? If you want to emphasize more than one aspect, that’s OK. There are blends of stereotypes, just as there are blends of emphasis.
OO: What are Domain Objects?
Domain objects provide a common ground in which developers and users can meet and discuss the application. Domain objects represent concepts that are familiar to users and experts in a specific field of interest.
For the developers, these domain objects are only the starting point for constructing a model of the domain and for developing the internal representations of these and additional concepts that will exist in the software machinery. Although the original, “common” concepts might not prove valuable in the executable system, they should be traceable through the design because they clearly express the stakeholders’ understanding and issues surrounding the application.
A domain model does not represent the entire domain as it is in the real world. It includes only the concepts that are needed to support the application.
OO: What are Application-Specific Objects?
An application model supplements the domain model with computer-specific objects for responding to the user, controlling execution, and connecting to outside resources.
OO: What is a Class? What are the roles of a class?
Classes play two roles. First, they act as factories, instantiating instances and implementing responsibilities on their behalf (constructor). Second, they act as an independent provider, serving clients in their neighborhood (methods)
Classes hold the “shape” of the objects that they make.
Relations among classes describe the myriad potential relations among run-time instances.
A class can also act as an object when the application needs only one of its kind (static).
What are the two types of relationships in an object model? Explain the difference.
There are only two types of relationships in an object model: composition and inheritance.
Both have analogs in a family tree. A composition relation is like a marriage between objects. It is dynamic, it happens during the participating objects’ lifetimes, and it can change. Objects can discard partners and get new partners to collaborate with. Inheritance relations are more like births into the family. Once it happens, it is forever. Just as both marriage and ancestry appear in the same family tree, composition and inheritance coexist in a single object model.