4

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:

  • Barchart
  • LineChart
  • PieChart

When creating these charts there are a few unknown variables.

  • Name of the chart series: This is the name that will be display and this differs from every line/bar/ pie slice

  • Period: Chart data is taken from a period of time, either a day or a week (every day Monday, Tuesday, Wednesday etc) a month (Jan,Feb,mar,April etc) or even time of day.(8pm,9pm etc).

  • Type of chart: of-course a difference is what type of chart the user wants to see.

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:

  • GUI: First the Gui is always separated from the actual logic i have no plans of demanding anything from the GUI except that it has to created in JavaFx and it has to have an instance of the Director class.

  • Director: The Director class is where all the action happens. First the client calls the director with what type of chart he wants to get, what period of time he wants data from and maybe what kind of data he wants to see. The client also sets the time period that he wishes to see the data in (day, week, month , year etc).

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.

  • Statistics: the statistics class then checks if it already contains data and if not it class for a list of object to the database:

  • DataBase: The database is quite straight forward it class for the data in the time period that client has send on (either on a day, week, month, year basis) creates the object(s) add them to a list and return it to the statistics class.

  • (back in the) statistic class the objects data are then calculated and returned to the director.

  • (Back in the director) The director now calls the chartBuilder to build a chart of the type specified by the client with the timeframe (which is an array or an arraylist of time, This is an option the client can set in the director using Director.setStandardTime(time)) the builder then creates the chart and table with the data obtained from the Director. The client is then able to call ChartBuilder.getChart() and add that to his layout.

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.

Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
  • Don't understand why 1) and 2) are different or why 3) would be something different than 1) or 2) - All three are based on some base class / interface and extend it. In one case you have to do `new BarGraph()` and in the other `new Barchart()` which sounds like it's pretty much the same with a different name. – zapl Nov 30 '12 at 01:23
  • The difference lies in the way of solving a problem like this and using the right design pattern to ensure the Best result! – Marc Rasmussen Nov 30 '12 at 20:50
  • What I meant primarily: your question does not clarify the details / differences enough to understand & give you an answer. Btw: what is the difference between a "graph" and a "chart" in your model? Aren't charts types of graphs? – zapl Nov 30 '12 at 21:59
  • @zapl added an update to my post – Marc Rasmussen Nov 30 '12 at 22:46
  • I agree with the above comments from @zapl. How are 1) and 2) competing ideas? I think you can use them together to find a good solution to your problem. I will formulate a more detailed answer over the next couple of days. Feel free to ping me a reminder. – Code-Apprentice Dec 03 '12 at 00:55
  • @Code-Guru please read my update. – Marc Rasmussen Dec 04 '12 at 15:01
  • @zapl please read my update – Marc Rasmussen Dec 04 '12 at 22:24
  • Hi Marc mange tak for accepten. Skriv hvis du har flere spørgsmål, jeg giver gerne en hånd. – Anders Sewerin Johansen Dec 08 '12 at 18:10

2 Answers2

3

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.

Community
  • 1
  • 1
Anders Johansen
  • 10,165
  • 7
  • 35
  • 52
  • Read it. Seems like you will also need Design Pattern "Builder" for the graph building (different ways of representing a structured product) and your "Director" object is Design Pattern "Mediator". The graph/data interaction is really a kind of Model/Controller/Viewer. Lastly you will probably be using Observer for interaction between your "Director" and the GUI. Sorry, posting from my secondary account... – Anders Sewerin Johansen Dec 05 '12 at 16:58
0

Take a look at EyeSee, and make a java implementation

Stephan Eggermont
  • 15,847
  • 1
  • 38
  • 65