Friday, August 28, 2009

Patterns - 003: Basic java patterns ( Interface )


Applying the Interface pattern, the common services offered by different service provider classes can be abstracted out and declared as a separate interface. Each of the service provider classes can be designed as implementers of this common interface.
With this arrangement, the client can safely assume the service provider object to be of the interface type.objects of different service provider classes can be treated as objects of the interface type. This enables the client to use different types of service provider objects in a seamless manner without requiring any changes. The client does not need to be altered even when a new service provider is introduced.

Prototype



Example



Let us build an application to calculate and display the salaries of dif ferent
employees of an organization with the categorization of designations as listed in

DesignationsCategory
Programmer, Designer and ConsultantCategory-A
Sales Rep, Sales Manager, Account RepCategory-B
C-Level ExecutivesCategory-n



Poor design

Let us assume that the application needs to consider only those employees whose designations are part of Category-A. And we design the application only for the Category-A. But when later found the Category-B. Then we have to Alter the emplyee class and make it compatible with the Category-B also. So this a result of bad poor design.








Correct Design









No comments:

Post a Comment