Tuesday, July 10, 2007

Supermarket anti-pattern

Consider the following scenario:
- dozens of classes used to define the object model
- one class to manage their update
- one class to manage their creation
- one class to manage their deletion
When the model had only 3 objects the class did not look so bad. But let's see what happen when the model was extended to 20 objects:
- nobody thought of refactoring the classes
- these classes have now 40-60 public methods

Problems:
- they have almost no cohesion
- almost unreadable
- full of duplicated code
- unstable

What the project achieved by doing it like this:
- one big class which does all
- few code dependencies; the rest of the code has to depend on only one class :)

I call this kind of "design" a Supermarket anti-pattern because we have everything in one single place :).

Don't do this in your projects!!

1 comment:

Thomas Koch said...

Hi Sebi,

my brother, who's doing only Java makes jokes about me, that PHP would not be a serious programming language. Thanks for this example, that there are also disasters written in Java in the wildernes!

Have a nice day,

Thomas