Lazy Class


  • A class isn't doing much ”its parents, children, or callers seem to be doing all the associated work, and there isn't enough behavior left in the class to justify its continued existence.


Typically, all the class's responsibilities have been moved to other places in the course of refactoring.

What to Do

  • If parents or children of the class seem like the right place for the class's behavior, fold it into one of them via Collapse Hierarchy .

  • Otherwise, fold its behavior into its caller via Inline Class .


Reduces size. Improves communication. Improves simplicity.


  • Sometimes a lazy class is present to communicate intent. You may have to balance communication versus simplicity.

Exercise 33 Swing Libraries. (Challenging).

The Swing Libraries have a pattern:


The AbstractXModel is the only implementation of the interface, and the DefaultXModel is the only subclass of the AbstractXModel. (Typically the abstract model has the notification handling built in, but it may support other things.)

  1. What advantages are there in having the model be an interface, separate from the AbstractXModel class?

  2. Why is this not an example of a Lazy Class?

  3. Should you adopt this three-class structure for your object structure?

See Appendix A for solutions.

Refactoring Workbook
Refactoring Workbook
ISBN: 0321109295
EAN: 2147483647
Year: 2003
Pages: 146

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: