From 7eac8e6a370203931c1901ebd9fea35c336c73d1 Mon Sep 17 00:00:00 2001 From: underscorediscovery Date: Wed, 18 Sep 2019 01:43:34 -0700 Subject: [PATCH] docs; encapsulation legibility fixes --- doc/site/classes.markdown | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/doc/site/classes.markdown b/doc/site/classes.markdown index c53444a3..a33f8df2 100644 --- a/doc/site/classes.markdown +++ b/doc/site/classes.markdown @@ -371,8 +371,8 @@ value is `null`. All fields are *private* in Wren—an object's fields can only be directly accessed from within methods defined on the object's class. -In short, if you want to make a property of an object visible, **you need to define a -getter to expose it**: +In short, if you want to make a property of an object visible, +**you need to define a getter to expose it**: :::wren class Rectangle { @@ -382,7 +382,8 @@ getter to expose it**: // ... } -To allow outside code to modify the field, **you need to provide setters to provide access**: +To allow outside code to modify the field, +**you need to provide setters to provide access**: :::wren class Rectangle { @@ -392,8 +393,8 @@ To allow outside code to modify the field, **you need to provide setters to prov This might be different from what you're used to, so here are two important facts: -- You can't access fields on another instance of your own class (unlike C++ and Java). - You can't access fields from a base class. +- You can't access fields on another instance of your own class. Here is an example in code: @@ -406,14 +407,17 @@ Here is an example in code: class Rectangle is Shape { construct new() { - //This will print null! _shape from the parent class is private, - //so we are really just reading `_shape` from `this`, which has not been set. + //This will print null! + //_shape from the parent class is private, + //we are reading `_shape` from `this`, + //which has not been set, so returns null. System.print("I am a %(_shape)") //a local variable, all variables are private _width = 10 var other = Rectangle.new() - //other._width is not accessible from here, + + //other._width is not accessible from here, //even though we are also a rectangle. The field //is private, and other._width is invalid syntax! }