Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What should I return ...
Message
De
05/02/2003 18:14:47
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Titre:
What should I return ...
Divers
Thread ID:
00749629
Message ID:
00749629
Vues:
51
I am creating class that builds a tree of objects and ending up with a collection of collections. See below. I am getting the impression that a procedure call like this:
loFooBranch = CreateObject([Collection])
loFooBranch = this.getFee(Feepk, loFooBranch)
May be bad practice. In the procedure getFee another object is added to the loFooBranch passed.

Should I be doing this instead?
loFooBranch = CreateObject([Collection])
loFiReturn = this.getFee(Feepk)
loFooBranch.add(loFiReturn.name, loFiReturn)
Any thoughts?
SOME SAMPLE CODE:  

do test

procedure test

  lotree = createobject('treecollection')
  loreturntree = lotree.getFoo([1])

  return .t.

endproc


define class treecollection as collection

  procedure init
    use FeeData in 0
    use FooData in 0
    select 0
    use FiData
    index on Fipk tag Fipk

  endproc

  procedure getFoo (tcpk)

    sele Feepk from FooData where Foopk = tcpk group by Feepk into cursor FeeCursor

    if reccount() = 0
      return .f.
    else
      loFooBranch = createobject([collection])
      loFooBranch.name = transform(Feepk)
    endif

    scan
      loFooBranch = this.getFee(Feepk, loFooBranch)
    endscan

    toMyRoot.add(loFiBranch.name,loFiBranch)

    return toMyRoot

  endproc

  procedure getFee (tcpk, toMyRoot)

    sele Fipk from FeeData where Feepk = tcpk group by Fipk into cursor FiCursor

    if reccount() = 0
      return .f.
    else
      loFeeBranch = createobject([collection])
      loFeeBranch.name = transform(Fipk)
    endif

    scan
      loFeeBranch = this.getFi(Fipk, loFeeBranch)
    endscan

    toMyRoot.add(loFeeBranch.name,loFeeBranch)

    return toMyRoot

  endproc

  procedure getFi (tcpk, toMyRoot)

    sele Fipk from FiData where Feepk = tcpk group by Fipk into cursor FiCursor

    if reccount() = 0
      return .f.
    else
      loFiBranch = createobject([collection])
      loFiBranch.name = transform(Fipk)
    endif

    scan
      loFiBranch.add(loFiBranch.name, Fipk)
    endscan

    toMyRoot.add(loFiBranch.name, loFiBranch)

    return toMyRoot

  endproc

enddefine
Carole Shaw
Fred Hutchinson Cancer Research Center

Eagles may soar, but weasels don't get sucked into jet engines.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform