Wiki

Changes between Version 1 and Version 2 of PartialTypes

Show
Ignore:
Timestamp:
01/08/13 01:30:11 (5 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PartialTypes

    v1 v2  
    11= Partial Types = 
    22 
    3 . 
     3Like 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. 
     4This is sometimes useful for large projects or classes made from partially computer generated code. 
     5 
     6Each partial class definition must have the same description (inheritance/interfaces supported) and each must be explicitly marked as  
     7'''is partial'''. 
     8 
     9More commonly the first portion of the partial class encountered has the full specification (inheritance, implementation, etc)[[BR]] 
     10while subsequent ones have only the same name and the required '''is partial''' clause   
     11 
     12== Example== 
     13 
     14in file1.cobra   
     15 
     16{{{ 
     17#!cobra 
     18namespace 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 
     34and in file2.cobra 
     35{{{ 
     36#!cobra 
     37 
     38namespace 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 
     50program is built specifying both files but result is a single class 
     51{{{ 
     52cobra file1.cobra file2.cobra 
     53}}} 
    454 
    555== See Also ==