Skip to content

Commit 05347e8

Browse files
committed
增加了对象初始化的一般方法
1 parent 399a4fa commit 05347e8

File tree

1 file changed

+145
-4
lines changed

1 file changed

+145
-4
lines changed

guide/object.lyx

Lines changed: 145 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#LyX 2.2 created this file. For more info see http://www.lyx.org/
2-
\lyxformat 508
1+
#LyX 2.3 created this file. For more info see http://www.lyx.org/
2+
\lyxformat 544
33
\begin_document
44
\begin_header
55
\save_transient_properties true
@@ -36,6 +36,8 @@ PackageOptions url hyphens
3636
\font_osf false
3737
\font_sf_scale 100 100
3838
\font_tt_scale 100 100
39+
\use_microtype false
40+
\use_dash_ligatures false
3941
\graphics default
4042
\default_output_format pdf4
4143
\output_sync 0
@@ -75,6 +77,7 @@ PackageOptions url hyphens
7577
\suppress_date false
7678
\justification true
7779
\use_refstyle 1
80+
\use_minted 0
7881
\boxbgcolor #d8daeb
7982
\index Index
8083
\shortcut idx
@@ -84,7 +87,10 @@ PackageOptions url hyphens
8487
\tocdepth 2
8588
\paragraph_separation indent
8689
\paragraph_indentation default
87-
\quotes_language english
90+
\is_math_indent 0
91+
\math_numbering_side default
92+
\quotes_style english
93+
\dynamic_quotes 0
8894
\papercolumns 1
8995
\papersides 2
9096
\paperpagestyle default
@@ -1326,6 +1332,7 @@ status open
13261332
\begin_inset CommandInset citation
13271333
LatexCommand cite
13281334
key "jvm-se8-specification"
1335+
literal "true"
13291336

13301337
\end_inset
13311338

@@ -2143,6 +2150,30 @@ status open
21432150
除了通过构造方法设置对象的初始状态外,也可以通过以下的方式进行对象的初始化操作:
21442151
\end_layout
21452152

2153+
\begin_layout Itemize
2154+
定义属性的同时初始化,比如
2155+
\begin_inset Flex Code
2156+
status open
2157+
2158+
\begin_layout Plain Layout
2159+
Circle
2160+
\end_layout
2161+
2162+
\end_inset
2163+
2164+
类中
2165+
\begin_inset Flex Code
2166+
status open
2167+
2168+
\begin_layout Plain Layout
2169+
Point
2170+
\end_layout
2171+
2172+
\end_inset
2173+
2174+
对象的处理方式。
2175+
\end_layout
2176+
21462177
\begin_layout Itemize
21472178
在创建对象后,直接访问对象的属性并设置希望的值。
21482179
\end_layout
@@ -2157,7 +2188,7 @@ status open
21572188

21582189
\begin_layout Standard
21592190
\begin_inset Flex Tip
2160-
status open
2191+
status collapsed
21612192

21622193
\begin_layout Plain Layout
21632194
定义有参构造方法时,要注意参数的个数不要太多,一般不要超过10个。太多的参数往往给使用者带来记忆和匹配的负担。如果需要大量的对象初始化操作,建议编写专门的方法初
@@ -2167,6 +2198,112 @@ status open
21672198
\end_inset
21682199

21692200

2201+
\end_layout
2202+
2203+
\begin_layout Standard
2204+
\begin_inset Flex Tip
2205+
status open
2206+
2207+
\begin_layout Plain Layout
2208+
对象属性的初始化一般有两种方式:定义的时候直接初始化和使用构造方法。在
2209+
\begin_inset ERT
2210+
status open
2211+
2212+
\begin_layout Plain Layout
2213+
2214+
2215+
\backslash
2216+
lstlistingname
2217+
\end_layout
2218+
2219+
\end_inset
2220+
2221+
2222+
\begin_inset CommandInset ref
2223+
LatexCommand ref
2224+
reference "sub322-Circle.java"
2225+
plural "false"
2226+
caps "false"
2227+
noprefix "false"
2228+
2229+
\end_inset
2230+
2231+
中采用了直接初始化
2232+
\begin_inset Flex Code
2233+
status open
2234+
2235+
\begin_layout Plain Layout
2236+
point
2237+
\end_layout
2238+
2239+
\end_inset
2240+
2241+
属性的方式,如果要使用构造方法初始化point属性,则
2242+
\begin_inset Flex Code
2243+
status open
2244+
2245+
\begin_layout Plain Layout
2246+
Circle
2247+
\end_layout
2248+
2249+
\end_inset
2250+
2251+
类的定义大致为:
2252+
\end_layout
2253+
2254+
\begin_layout Plain Layout
2255+
\begin_inset listings
2256+
inline false
2257+
status open
2258+
2259+
\begin_layout Plain Layout
2260+
2261+
public class Circle{
2262+
\end_layout
2263+
2264+
\begin_layout Plain Layout
2265+
2266+
Point origin;
2267+
\end_layout
2268+
2269+
\begin_layout Plain Layout
2270+
2271+
...
2272+
\end_layout
2273+
2274+
\begin_layout Plain Layout
2275+
2276+
public Circle(){
2277+
\end_layout
2278+
2279+
\begin_layout Plain Layout
2280+
2281+
origin = new Point();
2282+
\end_layout
2283+
2284+
\begin_layout Plain Layout
2285+
2286+
}
2287+
\end_layout
2288+
2289+
\begin_layout Plain Layout
2290+
2291+
...
2292+
\end_layout
2293+
2294+
\begin_layout Plain Layout
2295+
2296+
}
2297+
\end_layout
2298+
2299+
\end_inset
2300+
2301+
2302+
\end_layout
2303+
2304+
\end_inset
2305+
2306+
21702307
\end_layout
21712308

21722309
\begin_layout Exercise
@@ -5190,13 +5327,15 @@ public class Client {
51905327
\begin_inset CommandInset citation
51915328
LatexCommand cite
51925329
key "design-pattern-4gangs"
5330+
literal "true"
51935331

51945332
\end_inset
51955333

51965334
、单例模式
51975335
\begin_inset CommandInset citation
51985336
LatexCommand cite
51995337
key "design-pattern-4gangs"
5338+
literal "true"
52005339

52015340
\end_inset
52025341

@@ -7461,6 +7600,7 @@ JDK源代码可以从
74617600
LatexCommand href
74627601
name "https://github.com/dmlloyd/openjdk"
74637602
target "https://github.com/dmlloyd/openjdk"
7603+
literal "false"
74647604

74657605
\end_inset
74667606

@@ -8816,6 +8956,7 @@ pier继承下来一样。SmartPrinter类其实是一个Facade类
88168956
\begin_inset CommandInset citation
88178957
LatexCommand cite
88188958
key "design-pattern-4gangs"
8959+
literal "true"
88198960

88208961
\end_inset
88218962

0 commit comments

Comments
 (0)