Browse Source

encapsulation modifs

abakobo 8 years ago
parent
commit
c24d0f36fc
2 changed files with 50 additions and 6 deletions
  1. 17 5
      modules/monkey/docs/language/misc.md
  2. 33 1
      modules/monkey/docs/language/user-types.md

+ 17 - 5
modules/monkey/docs/language/misc.md

@@ -1,15 +1,27 @@
 ### Miscellaneous
 
-#### Encapsulation
+#### File Encapsulation
 
-There are three Levels of encapsulation in monkey2: `Public`, `Protected` and `Private`. `Public` and `Private` are applicable to variables, functions, structs, classes, interfaces. `Protected` can only be used inside a class, struct or interface.
+There are two Levels of encapsulation at .monkey2 source files scope: `Public`and `Private` (`Protected` can only be used inside a class, struct or interface).
 
-`Public` can be accessed from anywhere. It is the default encapsulation level.
+`Public` can be accessed from anywhere. It is the default encapsulation level. Code existing in the same source file have also acces to expressions declared as `Private`.
 
-`Protected` members can only be accessed by the base class and the derived ones or by class/struct extentions. Code existing in the same source file have acces to `Protected` too.
+example:
+```
+Namespace myapp
+#Import "<std>"
+Using std..
+
+Function Main()
+	SayHello()
+End
 
-`Private` members can only be accessed by the base class. Code existing in the same source file have acces to `Private`.
+Private 'this section won't be accessible in other imported files
 
+Function SayHello()
+  Print "Hello"
+End
+```
 
 #### Code lines splitting
 

+ 33 - 1
modules/monkey/docs/language/user-types.md

@@ -185,7 +185,7 @@ Local v:=New Vec2
 Print v
 ```
 
-We no longer need to use '.ToString()' when printing the string. Since Print() takes a string argument, and Vec2 has a conversion operator that returns a string, the conversion  operator is automatically called for you.
+We no longer need to use '.ToString()' when printing the string. Since Print() takes a string argument, and Vec2 has a conversion operator that returns a string, the conversion operator is automatically called for you.
 
 #### Extensions
 
@@ -202,3 +202,35 @@ Struct Foo Extension
 	End
 End
 ```
+
+#### Encapsulation
+
+There are three Levels of encapsulation for class and struct members:
+
+-`Public` members can be accessed from anywhere. It is the default encapsulation level.
+
+-`Protected` members can only be accessed by the base class and the derived ones or by class/struct extensions. Code existing in the same source file have acces to `Protected` members too.
+
+`Private` members can only be accessed by the base class. Code existing in the same source file have acces to `Private` members too.
+
+example:
+```
+Class Foo
+
+	'public by default'
+	Field i:Int
+
+	Protected
+
+	Field someProtectedThing:Int
+
+	Method doSomething()
+		Print "Doing something"
+	End
+
+	Private
+
+	Field _somePrivateThing:String
+
+End
+```