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

8.9. A Little Prefactoring

We modified the design as the code was being written. The following prefactoring guidelines suggested these modifications.

8.9.1. Splitters Versus Lumpers

The com.samscdrental.importexport package contains classes related to importing the data from text files:

    AddFromFileInterface.java
    CDDiscDataAccessImportExport.java
    CDDiscImportExport.java
    CDReleaseDataAccessImportExport.java
    CDReleaseImportExport.java
    CustomerDataAccesstExport.java
    CustomerImportExport.java
    DataAccessImportExportHelper.java

Tim and I originally started to place the method to import data from a file in each collection class, such as CustomerDataAccess. If the external representation of the data changed, the method in each class would have to change. Taking the "Split Versus Lump" approach, the import methods were separated into their own classes (e.g., CustomerDataAccessImportExport). Each class with an external representation (e.g., Customer) has a corresponding class (CustomerImportExport) that contains the import method (parseLine( )).

The data file format is one object per line. Each line contains the attribute values separated by a vertical bar (|). The collection class, such as CustomerDataAccessImportExport, reads the lines and handles file-oriented errors. The corresponding CustomerImportExport class parses each line and deals with attribute value errors.

8.9.2. Adopt a Prefactoring Attitude

The collections are made persistent using Java object serialization. The stored ...

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