Where Are The Objects?

Source: comp.object
Date: 04-Apr-98

Related Sites


o-< Problem: How do you find the objects for an object oriented design?
Start with a domain model (the objects from the problem domain) and elaborate it?
Start with a static model (class diagrams) and then use it to implement use cases?
Start with a dynamic model (collaboration/interaction diagrams) and then find classes that support it?


o-< Robert C. Martin wrote:

Neither class diagrams nor collaboration diagrams take precedence. It does not matter which ones you start with. The important thing is that you should avoid doing too much of one kind, without balancing them with the other kind. Class diagrams cannot stand alone. Neither can collaboration diagrams. They reinforce each other, and need to be developed concurrently with each other.

Failure to develop these diagrams concurrently will result in dynamic models that cannot be supported statically, or static models that cannot be implemented dynamically. Moreover, you will be heavily vested in the models that you have created, and will find it difficult to change them.

[About starting by creating a domain model, and elaborating it to a design:]
I have no trouble with building a domain model as a way to provide vocabulary and precision to the requirements document. But I do not believe that it is prudent to consider the domain model to be the precursor of a design.

Designs based strictly upon the domain model will probably wind up being too concrete; and too tied to the details of the domain. When we design we try to find the overreaching abstractions that make such details irrelevant. In so doing, we create a design that is valid for the class of domains, of which our domain model is just a single instance.

[And in another post:]
Of course this begs the question: "What is the starting point of a design?". The answer: The creative insight of the engineers. By taking a step (or two) back, and looking at the problem (and its environs) from many different angles, the engineers hunt for the abstraction that underlies the problem. This abstraction will then imply a solution. The solution may look nothing at all like the domain model.


o-< Patrick Logan provided an example of how basing a design on the domain model may break code:

For example, many years ago I joined a company that produced software for designing electronics. At the time I joined the industry was moving from gate level design (ANDs and ORs) to hardware description languages that allow abstract data types. All of the existing software was designed specifically for representing digital bits, i.e. 1s and 0s. Even though many of the software modules could have been applied to abstract values, they could not because they were too domain dependent.

This may be an extreme example. Many years earlier, it would have been difficult to anticipate the need for abstraction, not to mention justify the cost of building it into the system. But it serves to illustrate what happens over and over again in all domains: details change, even details that appear to be "central" to the domain.


o-< More Info:

Robert C. Martin wrote a series of articles about this subject in the C++ Report:

Kent Beck and Ward Cunningham, A Laboratory For Teaching Object-Oriented Thinking
(This article presents CRC cards, which are a good technique for finding objects: "Design with the cards tends to progress from knowns to unknowns, as opposed to top-down or bottom up.")