Changes between Version 4 and Version 5 of AccessModifiers
- Timestamp:
- 01/16/13 00:02:09 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AccessModifiers
v4 v5 1 1 = Access Modifiers = 2 2 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.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. 5 5 6 6 Method Access modifiers … … 12 12 13 13 Valid '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''') 15 15 * '''shared''' - Specifies Class (static) method or variable, 16 * '''virtual''', '''nonvirtual''' - on methods, specifies that the method overridable or not17 * '''override''', '''new''' - on methods specifies that a method is overriding or replacing a baseclass method of samesignature16 * '''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 18 18 * '''public''', '''protected''', '''private''', '''internal''' - specifies item visibility 19 19 * '''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. 20 24 21 25 Separate multiple modifiers with ''',''' e.g .... is protected, override 22 26 27 28 29 == Item Visibility == 30 31 Visibility (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 37 These modifiers cannot always map exactly as specified to backend supported visibility layers so best to treat them as decreasing 38 levels of advisory visbility as given above. 39 23 40 == Notes and Examples == 24 41 25 is fake::26 temporary for defining class/method api without implementation42 * is extern:: 43 - temporary for defining class/method api without implementation 27 44 e.g 28 45 {{{ 29 46 #!cobra 30 class TextWriter 31 is fake 47 class TextWriter is extern 32 48 33 49 get newLine as String … … 35 51 }}} 36 52 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)) 57 e.g 58 {{{ 59 #!cobra 60 class Runner 61 def main is shared 62 print 'main class for Runner' 63 }}} 41 64 42 is public/protected/private::43 on class, instance variableor 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) 45 68 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. 49 72 50 is virtual::51 method is redefinable (default)73 * is virtual:: 74 - method is redefinable/subclassable (default) 52 75 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. 58 78 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 61 86 been inherited from a baseclass. 62 87 e.g … … 70 95 class Car inherits Vehicle 71 96 72 def drive is new 97 def drive is new # replaces superclass method 73 98 pass 74 99 }}} … … 77 102 you must specify '''is override''' or specify '''is new''' 78 103 or 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]