Wiki

Changes between Version 4 and Version 5 of AccessModifiers

Show
Ignore:
Timestamp:
01/16/13 00:02:09 (7 years ago)
Author:
hopscc
Comment:

Update

Legend:

Unmodified
Added
Removed
Modified
  • AccessModifiers

    v4 v5  
    11= Access Modifiers = 
    22 
    3 Access Modifiers can be specified  on Classes, Class (instance and class) variables and methods to set their visibility and accessibility[[BR]] 
    4 These are also called 'isNames' in the Cobra doc and Discussion since they're specified with a leading '''is''' keyword. 
     3Access Modifiers can be specified  on Classes, class (instance and class) variables and methods to set their visibility and accessibility[[BR]] 
     4These are also called 'isNames' in the Cobra doc and discussion since they're specified with a leading '''is''' keyword. 
    55 
    66Method Access modifiers 
     
    1212 
    1313Valid 'is' keywords are  
    14  *       '''fake''' - specifies item has no implementation - a placeholder 
     14 *       '''fake''' - specifies item has no implementation - a placeholder (deprecated in favor of '''extern''') 
    1515 *       '''shared''' - Specifies Class (static) method or variable,  
    16  *       '''virtual''',   '''nonvirtual''' -  on methods, specifies that the method overridable or not  
    17  *       '''override''', '''new'''         - on methods specifies that a method is overriding or replacing a baseclass method of same signature 
     16 *       '''virtual''',   '''nonvirtual''' -  on methods, specifies that the method is overridable or not  
     17 *       '''override''', '''new'''         -  on methods specifies that a method is overriding or replacing a baseclass method of the same signature 
    1818 *       '''public''', '''protected''', '''private''', '''internal''' - specifies item visibility  
    1919 *       '''abstract''' - specifies a template only, subclasses must define fully 
     20 *       '''extern''' - item has no implementation and is defined elsewhere (outside a cobra file) 
     21 *       '''partial''' - on class types - specifies that the type is defined across multiple files                                
     22 *       '''readonly''' specifies that a variable or field cannot be modified.  
     23            It must be initialised as early as possible and cannot have its value modified after. 
    2024 
    2125Separate multiple modifiers with ''',''' e.g    ....  is protected, override 
    22       
     26 
     27 
     28 
     29== Item Visibility == 
     30 
     31Visibility (or accessibility) denotes the access to types or type variables (fields)  
     32 * public    -  the most permissive access level. There are no restrictions on accessing public members or public types. 
     33 * protected - access is limited to the containing class or types derived from the containing class. 
     34 * private   - access is limited to the containing type. 
     35 * internal  - access is limited to the current assembly (or packaging entity). 
     36 
     37These modifiers cannot always map exactly as specified to backend supported visibility layers so best to treat them as decreasing 
     38levels of advisory visbility as given above. 
     39    
    2340== Notes and Examples == 
    2441 
    25     is fake:: 
    26        temporary for defining class/method api without implementation 
     42    * is extern:: 
     43       - temporary for defining class/method api without implementation 
    2744e.g 
    2845{{{  
    2946#!cobra 
    30 class TextWriter 
    31     is fake 
     47class TextWriter is extern 
    3248 
    3349    get newLine as String 
     
    3551}}} 
    3652    
    37     is shared:: 
    38         on instance variable makes it a class variable. 
    39         on method makes it a class method 
    40             (effect is same as static (in C#, Java)) 
     53    * is shared:: 
     54        - on instance variable makes it a class variable. 
     55        - on method makes it a class method 
     56        -     (effect is same as static (in C#, Java)) 
     57e.g 
     58{{{  
     59#!cobra 
     60class Runner 
     61   def main is shared 
     62      print 'main class for Runner' 
     63}}} 
    4164 
    42     is public/protected/private:: 
    43         on class, instance variable or method(s) 
    44         adjust visibility (default public) 
     65    * is public/protected/private/internal:: 
     66         - on class, instance variable or method(s) 
     67         - adjust visibility (default public) 
    4568 
    46     is abstract:: 
    47         on class or method(s) 
    48         Specifies item as a template for subclasses to provide implementation of. 
     69    * is abstract:: 
     70        - on class or method(s) 
     71        - Specifies item as a template for subclasses to provide a concrete implementation of. 
    4972 
    50     is virtual:: 
    51        method is redefinable (default) 
     73    * is virtual:: 
     74       - method is redefinable/subclassable (default) 
    5275 
    53     is nonvirtual::     
    54         method is not redefinable 
    55      
    56     is override:: 
    57         Specifies that this method implementation is a redefinition of an existing(shadowed virtual or abstract) method defined in a superclass 
     76    * is nonvirtual::     
     77        - method is not redefinable, cannot be subclassed. 
    5878 
    59     is new::  
    60         Designate that this method is a new one that hides the one that would have  
     79    * is override:: 
     80        - on a method 
     81        - Specifies that this method implementation is a redefinition of an existing(shadowed virtual or abstract) method defined in a superclass 
     82 
     83    * is new:: 
     84       - on a method  
     85       - designate that this method is a new one that hides the one that would have  
    6186        been inherited from a baseclass. 
    6287        e.g 
     
    7095class Car inherits Vehicle 
    7196 
    72     def drive is new 
     97    def drive is new  # replaces superclass method 
    7398       pass 
    7499}}} 
     
    77102you must specify '''is override''' or specify '''is new'''  
    78103or use '''base.''' in the implementation (which is an implicit '''is override''')    
     104 
     105 
     106    * is partial:: 
     107       - on class types ( class, structures, interfaces) 
     108       - indicates that the type is defined across multiple files. Each piece so defined must be so tagged.  
     109       - Idiomatically the first file compiled should have the full declaration (inheritance, attrinutes etc) and the remainder have only the access modifies ( including 'partial') 
     110 
     111    * is readonly:: 
     112      - on variables (local and type) 
     113      - indicates that the variable cannot have its value changed 
     114      - the variable must be assigned to (explicitly initialised) on declaration or (for class type variables) must be initialised in the classes initialiser method. 
     115 
     116== See also == 
     117[http://msdn.microsoft.com/en-us/library/vstudio/wxh6fsc7.aspx C# reference Access Modifiers] 
     118 
     119[http://msdn.microsoft.com/en-us/library/ba0a1yw2%28v=vs.71%29.aspx C# Accessibility Levels] 
     120 
     121[http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html Java Access Modifiers]