3 | | . |
| 3 | 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. |
| 4 | This is sometimes useful for large projects or classes made from partially computer generated code. |
| 5 | |
| 6 | Each partial class definition must have the same description (inheritance/interfaces supported) and each must be explicitly marked as |
| 7 | '''is partial'''. |
| 8 | |
| 9 | More commonly the first portion of the partial class encountered has the full specification (inheritance, implementation, etc)[[BR]] |
| 10 | while subsequent ones have only the same name and the required '''is partial''' clause |
| 11 | |
| 12 | == Example== |
| 13 | |
| 14 | in file1.cobra |
| 15 | |
| 16 | {{{ |
| 17 | #!cobra |
| 18 | namespace PC |
| 19 | interface IBCall |
| 20 | def methodB |
| 21 | |
| 22 | class A inherits Object implements IBCall is partial |
| 23 | var num = 0 |
| 24 | |
| 25 | def main is shared |
| 26 | a = A() |
| 27 | a.methodA |
| 28 | |
| 29 | def methodA |
| 30 | print 'A.methodA' |
| 31 | .methodB |
| 32 | }}} |
| 33 | |
| 34 | and in file2.cobra |
| 35 | {{{ |
| 36 | #!cobra |
| 37 | |
| 38 | namespace PC |
| 39 | |
| 40 | class A is partial |
| 41 | def methodB |
| 42 | print 'A.methodB' |
| 43 | _methodC |
| 44 | |
| 45 | def _methodC |
| 46 | print 'A._methodC' |
| 47 | .num = 99 |
| 48 | }}} |
| 49 | |
| 50 | program is built specifying both files but result is a single class |
| 51 | {{{ |
| 52 | cobra file1.cobra file2.cobra |
| 53 | }}} |