Discovering and Documenting Classes

Steven Zeil

Last modified: Dec 19, 2017
Contents:

1 Classification

Classification: Where do Classes Come From?

A key step in any OO analysis or design is identifying the appropriate classes.


Grouping Objects into Classes

We may identify groups of objects as a class because they have common

2 Driving the classification process

Where do we get the information from which we can identify classes during analysis?

The “program as simulation” philosophy suggests that we should be looking for a model of the “real world”.


Working from Informal Descriptions

Generally, this is done at the start of construction of a domain model or, if no domain model is needed, of the analysis model.

A fairly simple way to get started is to scan the informal statement looking for noun phrases and verb phrases

This doesn’t scale well to large projects/documents, but it is simple and often a useful starting point.

After that, we move on by exploiting our knowledge to assign the responsibilities to the appropriate and to classes, refine our choice of classes and responsibilities.


Use-Case analysis

A use-case is a particular pattern of usage, a scenario that begins with some user of the system initiating a transaction or sequence of related events.

We analyze use-cases to discover the

More on this in later lessons.

3 Informal Documentation: CRC Cards


CRC Cards

Early in our development process, we won’t want to be slowed down by the need to construct detailed documentation that looks “pretty” enough to show people outside our team (management or domain experts).

CRC cards are a popular way of capturing early classification steps.


CRC

CRC (Class, Responsibility, & Collaborators) cards are a useful tool during early analysis, especially during team discussions.

They are not exactly a high-tech tool:


CRC Cards are Informal Documentation

3.1 CRC Card Layout


CRC Card Layout

ClassName
responsibility 1 collaborator 1
responsibility 2 collaborator 2
responsibility 3  

CRC Card Example

Librarian
Handles checkout and checkin of publications Patrons
Reshelves books Publications
Manages new acquisitions of publications Inventory
Has name, ID#, branch assignment Catalog

3.2 Assigning Responsibilities


Assigning Responsibilities Example

For example, if I were told “a library patron will give a librarian a book to be checked out”, I would model this as

Librarian
Handles checkout of books for patrons   
...   
Patron
    Librarian

but not as

Librarian
       
Patron
Asks librarian to check out book Librarian

When A does B to C

A useful rule of thumb is that if “A does B to C”, then

In pseudo-code terms, we might say

void A::fulfillSomeOtherResponsibilityOfA(C c1)
{
   ⋮
  c1.B();
   ⋮
}

Containers

A variation on this rule of thumb occurs when managing collections.

If I told you that “the librarian adds the book’s metadata to the catalog”, I would expect you to model that as

Catalog
Permits addition of metadata   

and not as

Metadata
Can be added to a catalog   

Metadata refers to the set of properties that identify and describe a document or other collection of data. Typical metadata fields are author, title, date of publication, etc. “Metadata” is a perfect example of the type of specialized vocabulary that the people working in the Library World would understand and that you as a software developer assigned to that world would need to learn to use when communicating with them.


Containers (cont.)

Again, by analogy with programming, we understand that if you had something like

vector<int> v;
set<int> myList;
   ⋮
v.push_back(23);
myList.insert (23);

You would never say:

23.insertInto (myList);

3.3 Attributes


Attributes

A common variation (used in the textbook) is to use the backs of the cards to list attributes.

We won’t do that. We’ll list known attributes among the responsibilities,

Librarian
Handles checkout and checkin of publications Patrons
Reshelves books Publications
Manages new acquisitions of publications Inventory
Has name, ID#, branch assignment Catalog

Attribute Conventions

3.4 Empty Columns


Empty Columns

It’s OK for one or the other column to wind up being empty.

These often correspond to external systems or people who are acting spontaneously to initiate some action.

3.5 Common Mistakes in CRC Cards


Common Mistakes in CRC Cards

Consequently, there’s no reason to list a collaborator twice.

In particular, if class B has an empty responsibilities column, it really can’t appear as a collaborator of anything at all!