Design Patterns in JFreeChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jfarmer
Posts: 10
Joined: Wed Jan 21, 2009 2:24 am

Design Patterns in JFreeChart

Post by jfarmer » Thu Jan 22, 2009 8:22 pm

I am trying to find design patterns in JFreeChart -- can anyone suggest some likely candidates?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Design Patterns in JFreeChart

Post by david.gilbert » Fri Jan 23, 2009 2:11 pm

jfarmer wrote:I am trying to find design patterns in JFreeChart -- can anyone suggest some likely candidates?
If you find some, let me know. :wink:

I did read the "gang of four" book once, and it was great. But it was like one of those books that says eat healthy food and exercise more - you know it is right, but you ignore the advice all the same.

Actually, someone did mock me once, hinting that I didn't understand the Factory pattern because JFreeChart's ChartFactory class so obviously doesn't use the Factory pattern. In fact, back when I chose the name ChartFactory (2000/2001?) I hadn't heard of design patterns at all, and thought that ChartFactory sounded like a good name for a class that *assembles* chart instances. I should have called it ClassThatAssemblesChartInstancesToSaveYouFiguringOutHowToDoIt. Oh well.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

jfarmer
Posts: 10
Joined: Wed Jan 21, 2009 2:24 am

Post by jfarmer » Fri Jan 23, 2009 4:06 pm

That's bad new about ChartFactory, that one seemed like a lock. :-) I may have found an Observer. I'll let you know what I find.

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Sun Jan 25, 2009 12:45 pm

The ChartFactory is a factory, there is no doubt about it.

The "holy book" mentions two factories: the "Abstract Factory" pattern, which I actually never used in the real world, and the pattern called "Factory Method". The ChartFactory class is a great example for having many factory methods.

The observer pattern is used in all EventListeners, so you'll find many of them.

The strategy pattern can be found in the various "Block" classes, they use a layout strategy that is expressed via the "Arrangement" class.

The BlockContainer is also a good example for a Composite pattern.

Whenever you add a border to a chart, you are deep inside a decorator pattern.

So dont trust David when he says he does not use or know about patterns. :)

The book itself only described what sane programmers (at this time) did for years. The reason the book became a success was not for its new and deep insights but for providing the programming community a well-defined set of names for the things each of them did in their daily life. Once they had the common names, it was a lot easier to talk about code.

jfarmer
Posts: 10
Joined: Wed Jan 21, 2009 2:24 am

Post by jfarmer » Sun Jan 25, 2009 5:13 pm

Many thanks!

Locked