Marc Rasmussen
Marc Rasmussen

Reputation: 20555

Creating a standard graph builder using OOP and Design Patterns

This is an example of my firms costum made chart with connected table.

This is an example of the lineChart with a connected table.

UPDATE my full idea enter image description here

i have been given this alot of thinking since i started this post and i have finally come up with an idea that i think is solid using the Builder pattern i want to you guys what you think and what issues you think that i might run into. First let me explain the full idea:

My Company need some sort of Standard graph with a connected table that they can use for all of their programs (This will give the programs a feeling that they are all alike (which they are)) Since most of these charts are alike i thought i could easy the pain of creating a new chart every time you have to make a new program or have to place the chart somewhere else.

My Company use three diffrent charts primarily:

When creating these charts there are a few unknown variables.

Last but not least the only difference between the chart creating lies within the Piechart, the pieChart is the only chart in Javafx that is not created from series but is created from an Observable list, so the pieChartBuilder has to use and insert the data in a different way than the others.

The picture above is Not an UML diagram it is a demonstration of how i plan my new program(s) to behave and adjust the design pattern, here is a walk through of what my thought are:

The Director then takes all of that data and class his instance of the statistic class asking the class for data that the director can then pass on the the Chart builder.

This is my idea. i Would love for you to comment on it. Thank you for reading and i will be looking forward to read all of your responses.

Upvotes: 4

Views: 2750

Answers (2)

Stephan Eggermont
Stephan Eggermont

Reputation: 15907

Take a look at EyeSee, and make a java implementation

Upvotes: 0

Anders Johansen
Anders Johansen

Reputation: 10455

The most common Design Patterns for graphics tasks are Decorator (often with a "fluent" interface), Prototype/Clone and Visitor. These will proably come in handy.

Decorator: For when you want to add attributes to your object incrementally. Such as:

final int radius = 100;
// With fluent interface
final Graphic boxedShadedCircle = new Circle(radius, 100, 100).shaded().boxed();
// Without fluent interface
final Graphic nonFLuentBoxedShadedCircle = new Boxed(new Shaded(new Circle(radius, 100, 100)));

Prototype/Clone: For when you want to be able to duplicate some object (copy/paste functionality). It's basically the interface Clonable.

Visitor: When you want to add functionality to objects without adding to the code in the actual object. Say, if your application is somehow scriptable. See this post for an example:Visitor pattern

Now to relate to your specific solutions:

It seems like Decorator would be a good way to implement your first solution proposal. Alternatively Template method or some sort of composition ("combine generic graph drawer with data object").

For your second solution, Factory seems appropriate.

I can't say which is best. It depends on your local circumstances. All implementations have pros and cons, and the trick is to pick the appropriate one where the pros outweigh the cons.

Updates for the updated question:

ChartBuilder: This should probably be design pattern "Builder". This dp is about representing or rendering an abstract description/product such as a document description or a data set in different ways.

Director: This is Design patter Mediator. Or Facade, depending on intent. Facade if you are "hiding away" a ball of crappy legacy code, Mediator if you are coordinating the interaction of several more modern classes. Lots of grey area here. If Director also handles interaction with the GUI (resize, hide etc) it's definitely Mediator.

Overall, your structure is model/viewer/controller. Director acts as controller, Statistics acts as model, chartBuilder acts as viewer.

It's not uncommon to have several design patterns overlap, as in having the controller act as mediator.

You may be happier if you implement the whole thing as request/response using design pattern Observer for the response, rather than as straight calls with return values. It's more flexible that way, and you can hide latency/calculation/database lookup in a thread better.

You may want to use Composite for chartBuilder. If you want to have several views on the data active at the same time, rather than just one.

Upvotes: 3

Related Questions