Design Patterns Java™ Workbook

(Michael S) #1
Appendix B. Solutions

public abstract CreditCheck createCreditCheck();


public abstract ShippingCheck createShippingCheck();
}


A user of your software can import com.oozinoz.check.* and then refer to whichever
factory he or she needs. For example, application code might contain:


// ...
CheckFactory f = CheckFactory.CANADA;
BillingCheck b = f.createBillingCheck();
// ...


SOLUTION 17.4....................................................................................................................................



  • An example justification: Placing country-specific classes in separate packages helps
    our developers at Oozinoz to organize our software and our development efforts. By
    placing the classes for each country in a separate package, we keep country-specific
    packages independent. We can be confident, for example, that U.S.-specific classes
    have no impact on Canada-specific classes. We can also add support for new countries
    easily. For example, when we start doing business with Mexico, we can create a new
    package that provides the check services we need in a way that makes sense in that
    country. This has the further advantage of letting us assign the mexico package to a
    developer who has expertise in working with services and data from Mexico.

  • An argument against: Although this separation is nice in theory, it's overwrought in
    practice. I'd rather have one package with all the classes in it, at least until we expand
    to nine or ten countries. In my development environment, this lets me see and compare
    all the classes of a given type at once.


SOLUTION 17.5....................................................................................................................................


Reasons for specifying different look-and-feel standards include the fol-lowing.



  • We might want to have one set of components for new users and one for power users.

  • We might have different display types, such as handheld and full-screen displays. For
    a smaller display, our standard components should typically be smaller. Even the
    difference between, say, a 15-inch and a 19-inch display might warrant different
    standard components.

  • We might want to distinguish major release versions of our application suite by
    including changes in look-and-feel. For example, we might change the standard
    background color from ivory to canary yellow when a user upgrades to version 3.0 of
    our application.In the call center, it will be instantly recognizable which version of our
    application a user is running.

  • For beta software, we might want to, say, put a red stripe around the outermost panel.


SOLUTION 17.6....................................................................................................................................


Figure B.22 shows a sample solution:

Free download pdf