9/08/2004

Facade Notes

Generally façades are implemented as concrete classes or as singletons or as helper static methods. Even design patterns workbook says “A facade provides an interface, but it does not use a Java interface. Rather, a facade is a class with methods that make it easy to use the classes in a subsystem”. Implementing facades as concrete classes should not be a qualification, in fact interface based facade implementations are better.

  • Concrete façade/singleton classes make testing client code difficult, e.g., client using a concrete facade that hides remote calls. We can’t test client code unless remote services needed by façade are running.
  • If implemented as interfaces, we can easily change implementations (even intent change to a bridge).
Are helper utility classes facades? Helpers and utilities simplify complex API usage by wrapping commonly used code. If helpers can abstract complete client needs to facaded API, then helpers are façades.

Do we need facades to standard APIs? Standard APIs are well documented, well understood and well designed. By standard APIs I mean subsystems like swing, jms etc. Wrapping rich APIs for your needs is difficult. Our facades tend to hide well needed APIs richness. Why do we need facades to well known standard APIs? Except for temporary advantage of hiding some of the (noisy) classes from client they are not really helpful. In the long run our facades to such apis tend to be maintenance headaches. So letting user deal with the standard apis is better. If needed we can have some helper classes to simplify some parts of it.

Does it mean data access objects, Object Relational Mapping tools, aren’t needed, aren’t they facades to standard APIs? Data access objects are not treated JDBC facades, they are helper classes to abstract a client modules persistence needs. ORM tools are defining new set of APIs with intent of providing persistence features for objects, their primary intent is not to hide JDBC layers.

Core J2EE's Session Façade, Fowler's Gateway, Business Service, Remote Façade are they facades? They certainly are, their specialized (overloaded) intent is to hide low level (remote/ session handling/ integration) abstractions by providing a high level user/application friendly interface. They hide noise (convert application requests to low level requests, convert low level exceptions to business exceptions etc.)

In the end Facade’s intent is to provide a consolidated complete unified cool API to a complex/noisy abstractions.

0 Comments:

Post a Comment

<< Home