Wiki
Version 2 (modified by hopscc, 5 years ago)

--

Partial Types

Like C#, cobra allows you to specify a class as a partial Type allowing you to spread the definition of a class across multiple source files. This is sometimes useful for large projects or classes made from partially computer generated code.

Each partial class definition must have the same description (inheritance/interfaces supported) and each must be explicitly marked as is partial.

More commonly the first portion of the partial class encountered has the full specification (inheritance, implementation, etc)
while subsequent ones have only the same name and the required is partial clause

== Example==

in file1.cobra

namespace PC
    interface IBCall
       def methodB

    class A inherits Object implements IBCall is partial
       var num = 0

       def main is shared
           a = A()
           a.methodA

       def methodA
           print 'A.methodA'
           .methodB

and in file2.cobra

namespace PC

    class A is partial 
       def methodB
           print 'A.methodB'
           _methodC

       def _methodC
           print 'A._methodC'
           .num = 99

program is built specifying both files but result is a single class

cobra file1.cobra file2.cobra

See Also