[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gambas-devel
Subject:    Re: [Gambas-devel] "Overriding" virtual classes
From:       Tobias Boege <tobias () gambas-buch ! de>
Date:       2014-06-24 10:53:17
Message-ID: 20140624105317.GB1035 () aurora
[Download RAW message or body]

On Mon, 23 Jun 2014, Tobias Boege wrote:
> A try will show how far I can get with the solution I just sent in another
> mail. If it's not satisfying, I'll return to this thread...
> 

I have almost all pieces collected. But take this sample expression (first
the variable/property/method name, then the class name in parentheses):

  myGraph (Graph)
    `-- .Vertices (.Graph.Enumerable)
          `-- [iVertex] (.Graph.Vertex)
	       `-- .OutEdges (.Graph.Enumerable)

This expression may be used as

  Dim iEdge As Integer

  For Each iEdge In myGraph.Vertices[iVertex].OutEdges
    Print "The vertex";; myGraph.Edges[iEdge].Destination;; "is adjacent to";; iVertex
  Next

This way, I have lots of different classes that inherit .Graph.Enumerable
which is just a class that has a _next() method. But this _next() method
needs to be implemented differently for different things to enumerate on a
graph, like vertices, edges or edges going out from a particular vertex.

You see, there is lots of things to be enumerated here and my problem is
that I don't want users to have like a half dozen (Graph.Vertices,
Graph.Edges, Graph.Vertices[i].InEdges, Graph.Vertices[i].OutEdges,
Graph.Vertices[i].Adjacent) classes to write which all just contain _next()
methods. (On the other hand, I do want to use virtual classes instead of
arrays to reduce memory usage for graphs that are implicitly defined by
another data structure (for which I gave an example yesterday).)

I thought of having like _nextVertex() and _nextEdge() methods in the
*Graph* class. Then I could write a .Graph.Vertices class which Inherits
.Graph.Enumerable and is responsible for iterating over the vertices of a
graph - once and for all in gb.data. No Gambas programmer would then have to
write their own .Graph.Enumerable class for vertices (and likewise with the
other enumerable things).

Its _next() method would only consist of a call to the _nextVertex() method
of the concrete Graph implementation. This way, we can preserve the syntax

  Dim iVertex As Integer

  For Each iVertex in myGraph.Vertices
    ' ...
  Next

But there is the overhead of the call to myGraph._nextVertex() from
.Graph.Vertices._next(), i.e. GB.GetFunction() and GB.Call() because the
actual Graph's _nextVertex() implementation or location is unknown at
compilation time.

The goal is, as I said, to reduce the number of short classes the user has
to write to implements their own Graph. In Java, the situation is a bit
better because there you can have nested classes which are easier to read
because they're *inside* the class they operate on and can also access their
private symbols.

Do you have a better idea? What I need is a way to iterate over the same
object in multiple ways, i.e. I need For-Each to be able to pick different
_next() implementations in the same class.

Regards,
Tobi

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


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Gambas-devel mailing list
Gambas-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic