Skip to content

Commit 9eda0aa

Browse files
ClémentClément
authored andcommitted
Light edits in the properties notes.
1 parent 55a707c commit 9eda0aa

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

source/lectures/oop/properties.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
tags:
33
- oop
44
---
@@ -82,9 +82,9 @@ tags:
8282
- Properties are members of an object, just like instance variables and methods
8383
- Access them with the "member access" operator, aka the dot operator
8484
- For example, `myRect.Width` will access the property we wrote, assuming `myRect` is a Rectangle
85-
- A complete example (available [as a complete solution](./code/projects/Properties_Example.zip)), where the "length" and "width" attributes are implemented with properties:
85+
- A complete example where the "length" and "width" attributes are implemented with properties:
8686
87-
```
87+
```{download="./code/projects/Properties_Example.zip"}
8888
!include code/projects/Properties_Example/Rectangle/Rectangle.cs
8989
```
9090
@@ -159,14 +159,14 @@ tags:
159159
```
160160
- Note however that if either the set or get accessor is not the "trivial" one, then automatic properties cannot be used and the other accessor must be specified.
161161
- For example, in the above code, simply writing `get;` instead of `get { return length; }` would give a compilation error.
162-
- Note that properties can exist without backing field, and they can be *read-only* (that is, without a set accessor) or *write-only* (that is, without a get accessor, but this is rarer).
162+
- Note that properties can exist without backing field, and they can be *read-only* (that is, without a set accessor) or *write-only* (that is, without a get accessor, but this is more rare).
163163
- An example of read-only property is as follows:
164164
165165
```
166166
class Circle
167167
{
168168
public decimal Diameter { get; set; }
169-
// The constructor below sets the value
169+
// The constructor below sets the value
170170
// of the property's backing field through
171171
// the property's set accessor.
172172
public Circle(decimal dP)
@@ -221,11 +221,11 @@ Putting together some of the elements discussed above, we can get for example th
221221

222222
### Simple Notation
223223

224-
- Since properties represent (or, rather, allow to access) attributes, they go in the "attributes" box (the second box)
225-
- If a property will simply "get" and "set" an instance variable of the same name, you do *not* need to write the instance variable in the box
224+
- Since properties represent (or, rather, allow to access) attributes, they go in the "attributes" box (the second box).
225+
- If a property will simply "get" and "set" an instance variable of the same name, you do *not* need to write the instance variable in the box, especially if those instance variables are not used anywhere other than through the property
226226
- No need to write both the property `Width` and the instance variable `width`
227-
- Syntax: `[+/-] «property» [name]: [type]` (where "«property»" is sometimes used in place of «property»).
228-
- Note that the access modifier (+ or -) is for the property, not the instance variable, so it is + if the property is `public` (which it usually is)
227+
- Syntax: `[+/-] «property» [name]: [type]` (where "<<property>>" is sometimes used in place of «property»).
228+
- Note that the access modifier (+ or -) is for the property, not the instance variable, so it is + if the property is `public` (which it usually is).
229229
- Example for `Rectangle`, assuming we converted both attributes to use properties instead of getters and setters:
230230

231231
!include diag/cla/Rectangle_with_properties.md

0 commit comments

Comments
 (0)