Upload
justin-fox
View
220
Download
2
Embed Size (px)
Citation preview
Chapter 10Classes and Objects: A Deeper Look
1
2
Classes
Classes are not just containers for methods◦ Virtually all are classes◦ Blueprint/Cookie Cutter/Recipe◦ Objects – instance of the class (new)◦ Type “prop” tab tab
OOP – vast topic
3
10.2 Time Class Case Study
4
Formatting: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspxPadding: http://msdn.microsoft.com/en-us/library/txafckwd.aspx
5
6
7
8
9
Classpublic Aprotected Binternal Cprivate D
Classpublic Aprotected B internal Cprivate D
SubClasspublic Aprotected Binternal Cprivate D
ASSEMBLY
SubClass (outside package)
public Aprotected B internal Cprivate D
Class (outside package)
public Aprotected B internal Cprivate D
Assembly is a chunk of precompiled code that can be executed by the .NET runtime environment. Usually, a .NET program consists of one or more assemblies
10.3 Controlling Access to Members
11
10.4 Referring to the Current Object’s Members with the this Reference
12
13
14
15
10.5 Time Class Case Study: Overloaded Constructors
16
It's the marker for Inheritance and/or the constructor call chain.
17
18
19
20
21
22
23
24
25
10.6 Default and Parameter-less Constructors
26
10.7 Composition
27
28
29
30
31
32
33
34
10.8 Garbage Collection and Destructors
35
10.9 static Class Members
36
37
38
39
40
static readonly field is set at run time, and can thus be modified by the containing class
the value of a const field is set to a compile time constant.
In the static readonly case, the containing class is allowed to modify it only in the variable declaration (through a variable initializer) in the static constructor (instance constructors, if it's not static)
static readonly is typically used if the type of the field is not allowed in a const declaration, or when the value is not known at compile time.
Instance readonly fields are also allowed.
Remember that for reference types, in both cases (static and instance) the readonly modifier only prevents you from assigning a new reference to the field. It specifically does not make immutable the object pointed to by the reference.
What is the difference between const and static readonly?
41
10.10 readonly Instance Variables
42
10.11 Data Abstraction and Encapsulation
43
10.12 Class View and Object Browser
44