LarissaHortencio10 / charts4j

Automatically exported from code.google.com/p/charts4j
Other
0 stars 0 forks source link

Add an ability of subclassing to GChart implementations #59

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
A part of style (color, size, etc...) of chart in an application is usually 
static.

In contrast, some axis labels and plot data is varying dynamically.

http://code.google.com/p/charts4j/source/browse/tags/v1.2/example/com/googlecode
/charts4j/BarChartExample.java#51

In this example, all of parameters to create charts need to be set each time.

To omit this botheration, I want to subclass GChart implementation and set 
default style in the subclass's constructor like this:
https://gist.github.com/1289106

However, constructors of the implementations of GChart is package private scope.

Would you like to define these constructors as protected scope?

Original issue reported on code.google.com by dai.0...@gmail.com on 15 Oct 2011 at 6:01

GoogleCodeExporter commented 8 years ago
Why do you have to do this via subclassing? Why not use object composition. 
Simply write a class that has a factory method that creates a chart with the 
styles you want. I was inspired by Josh Bloch's Effective Java when I wrote 
this library. In short, inheritance breaks encapsulation.

Original comment by Julien.C...@gmail.com on 15 Oct 2011 at 10:44

GoogleCodeExporter commented 8 years ago
In fact, an inheritance sometimes breaks encapsulation.  So I was tried to 
implement my specialized charts by not inheritance but composition.

At that time, I realized that my charts have hierarchical structure and "is-a" 
relations each other.  The formal solution for this situation is composition.  
I know I should build my own class structure same as tree of GCharts.  However, 
as a design decision, I may select inheritance to prevent a complexity more 
than needed.  I think that it would be a better not to inhibit potential to 
select inheritance.

Humm...  I have also read Effective Java.  So I know the risk of subclassing 
abuse and think you may be right.  I'll try to composy my hierarchical 
structure again.

Thank you.

Original comment by dai.0...@gmail.com on 15 Oct 2011 at 1:28