Skip to Main Content
Prefactoring
book

Prefactoring

by Ken Pugh
September 2005
Intermediate to advanced content levelIntermediate to advanced
240 pages
6h 28m
English
O'Reilly Media, Inc.
Content preview from Prefactoring

2.5. Clumping

When Sam described his customers in detail, he mentioned that he needed to keep track of each customer's home address, including street, city, state, and Zip Code, as well as credit card billing address, including street, city, state, and Zip Code.

I asked him, "Do both of those addresses contain the same information?"

He replied affirmatively.

I said, "Then let's just describe the combination as an Address. That way, you don't have to keep mentioning all the parts unless there is something different about them."

"OK," he answered.

We clumped the data into a class, as follows:

    class Address
        {
        String line1;
        String line2;
        String city;
        String state;
        String zip;
        }

At this point, we simply clump the related data, even though we have not assigned any behavior to the class. This data object helps in abstraction and in cutting down parameter lists. Even though the class contains only data at this point, we might be able to assign responsibility to it later on.[*]

[*] Not all objects have behavior. Objects that contain just data (sometimes called data transfer objects) are useful in interfacing with GUI classes and passing as objects between networked systems. Data transfer objects are covered in Chapter 7.

Clumping and lumping look similar, but they have distinctly different meanings. Clumping involves combining a set of attributes into a single named concept. The attributes should form a cohesive whole. Lumping involves using a single name for two different concepts. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Understanding Unittest.Mock

Understanding Unittest.Mock

Mario Corchero
Java™ Performance

Java™ Performance

Charlie Hunt, Binu John

Publisher Resources

ISBN: 0596008740Supplemental ContentCatalog PageErrata