[Gambas-user] The Class keyword

Tobias Boege taboege at ...626...
Fri Jun 27 11:42:06 CEST 2014


On Fri, 27 Jun 2014, B Bruen wrote:
> As in :
> CLASS Identifier
>    Declares to the compiler that Identifier can be used as a class name.	
> 
> I am unsure of what this keyword really achieves.  Specifically, I am having trouble understanding the help paragraph:
> "This keyword can be useful if you want to write some optional code in a component that needs a class from a component that is not necessarily loaded by the main project using this component."
> 

Suppose you implement a Graph class in gb.data which uses an adjacency
matrix. So you have the normal graph stuff in the interface but also maybe
a Matrix property that is specific to the Graph implementation via an
adjacency matrix - and this property returns that matrix.

This is actually useful because you may want to do arithmetic on this matrix
to find connected components, the number of triangles in the graph, etc..

However, you would want the datatype of the Matrix property to be the Matrix
class of gb.gsl or the like so that users can readily operate on it. But you
may also notice that some users don't really care about the matrix - they
just want *some* graph or adjacency matrices scale well in their application
- and are bothered by the dependency of gb.gsl you have just imposed.

Therefore, leave gb.gsl out and use "Class Matrix" in your Graph class.
Those users who want to use the Matrix property will have to load gb.gsl
themselves and everyone is happy.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list