Lazy Class


Symptoms

  • 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.

Causes

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 .

Payoff

Reduces size. Improves communication. Improves simplicity.

Contraindications

  • 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:

graphics/09inf01.gif

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

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net