Академический Документы
Профессиональный Документы
Культура Документы
1
004.43
1
- . .: , 2014. 304 .: .
( ).
ISBN 978-5-496-00793-1
- , C++, Java, C#, Visual Basic, .NET, Ruby Objective-C. ,
-, JavaScript, Python PHP.
- , , ,
, . , ,
(, Objective-C, VB .NET, C++, C#, .NET Java)
(, UML), ,
- .
,
- ,
.
32.988.02-018.1
004.43
Addison-Wesley Longman. .
.
, , , . , ,
, .
ISBN 978-0321861276 .
ISBN 978-5-496-00793-1
............................................................................................................... 13
...................................................................................................... 14
.................................................................................................... 14
............................................................................................................... 15
1. - .................................. 20
2. ............................................................................... 51
3. - ............................... 67
4. ....................................................................................... 88
5. ................................................100
6. ..........................................117
7. ....................................................................131
8. :
.............................................153
9. - .........180
10. ................................................................194
11. : XML JSON.......................................208
12. : ,
...................................................................................229
13. -, ..............246
14. - .............................................272
15. .....................................................................285
............................................................................................................... 13
...................................................................................................... 14
.................................................................................................... 14
............................................................................................................... 15
.............................................................................. 17
................................................................................................. 17
, ..................................................................... 18
, ................................................................................ 19
1. - .................................. 20
................................................................................. 20
....................................................................... 21
-........ 23
-....................... 27
...................................................................... 27
- ............................................... 27
..................................................................................................... 28
.............................................................................................. 28
......................................................................................... 28
....................................................................................................... 32
........................................................................................... 33
........................................................................................................... 35
............................................................................................................. 35
....................................................................................................... 35
....................... 36
............................................................................. 36
...................................................................................................... 37
....................................................................................................... 38
/................................... 38
/................................................... 39
......................................................................................................... 40
................................................................................. 41
.............................................................................................. 42
................................................................. 43
......................................................................................................... 44
............................................................................................................ 47
.............................................................................................. 47
...................................................................... 48
................................................................................................................... 48
, ......................................................... 48
7
2. ............................................................................... 51
.......................................................... 52
........................................................................................................ 54
....................................................................................................... 54
/...................................................................... 55
................... 59
........ 62
............................................................................. 63
......................................................................................... 64
, ..................................................................... 64
................................................................ 64
................................................................................. 65
................................................................................................................... 66
.................................................................................................................... 66
3. - ............................... 67
.......................................................................................................... 67
....................................................... 68
................................................................... 68
............................................................................... 68
................................................. 69
.......................................................................................... 70
UML ............................................. 71
........................................................................ 73
........................................................................ 73
.................................................................................................. 74
................................................................................... 74
............ 75
........................ 75
............................................................................... 76
.................................................................................. 78
......................................................................................... 78
............................................................................................ 80
.............................................................................................. 82
........................................................................................... 83
................................................................................ 84
............................................................................................ 85
................................................................................................................... 86
.................................................................................................................... 86
, ......................................................... 87
4. ....................................................................................... 88
.............................................................................................................. 88
.......................................................................................................... 90
................................................................................................................. 90
.......................................................................................................... 92
...................................................................................................... 94
.............................................................................. 96
................................................................................. 97
................................................................................................................... 97
.................................................................................................................... 97
, ......................................................... 98
5. ................................................100
..........................................................................100
.....................................................................101
.................................................................101
........................................................................................102
(,, )................103
....................................................................104
.............................104
.........................................105
............................................106
.............................................................106
.........................................................................106
...........................................................107
...............108
.......................................................108
.........................................................................109
........................................................111
............................................111
...............................................................................112
....................................................................114
..................................................................................................................115
...................................................................................................................115
, ........................................................116
6. ..........................................117
............................................................................117
..........................................................121
..................................................................121
.............................................................................................122
............................................122
......................................................................................123
................................................123
......................................123
............................................123
.................................................123
................................................................................................124
...................................................................................125
...........................................................126
.................................................................128
..............................................................129
..................................................................................................................130
...................................................................................................................130
7. ....................................................................131
......................................................................131
........................................................................................................133
............................................................................135
.........................................................................................136
9
...........................................................................................................138
-
............................................................................................................141
.....................................................142
.................................................................144
...............................................................................144
, ...................................148
..................................................................................................................150
...................................................................................................................150
, ........................................................151
8. :
.............................................153
: ?.....................................................................153
.............................................................................................154
.................................................................................................156
.........................................................................................157
.....................................................................................................160
...................................................................................162
, ................................................165
.....................................................................................165
.......................................................................168
...............................................................168
, ................................................168
....................................................169
.................................................................172
UML....................................................................................172
..................................................................................................................176
...................................................................................................................177
, ........................................................177
9. - .........180
.........................................................................................180
...............................................................................................182
...................................................................................................184
........................................................................................................185
......................................................................................................186
...................................186
.......................................................................................187
.....................................................................................................188
, .........................................190
...........................................................................191
: ............................................................................191
..................................................................................................................193
...................................................................................................................193
10. ................................................................194
UML........................................................................................................194
.................................................................................195
.................................................................................................197
10
..........................................................................................................197
............................................................................................................197
.............................................................................................198
........................................................................................................199
...........................................................................................................200
...........................................................................................................201
........................................................................................................202
......................................................................................................202
.....................................................................................................204
..................................................................................................................206
...................................................................................................................206
11. : XML JSON.......................................208
............................................................................................209
XML .......................................................................................................................210
XML HTML........................................................................211
XML - ................................212
.............................................................213
(DTD)................................214
XML-......................................216
CSS...............................................................................................221
JavaScript Object Notation (JSON)............................................................................223
..................................................................................................................228
...................................................................................................................228
12. : ,
...................................................................................229
, ......................................229
....................................................................231
.......................................................................................232
................................................................234
?......................................................................................235
XML ......................................................236
........................................................................238
..................................................................................................................242
...................................................................................................................242
, ........................................................243
13. -, ..............246
.................................................................246
.............................................................247
JavaScript...................................................250
-.......................................................................................253
JavaScript-...........................................................................................253
-...............................................................255
.......................................................................................256
.......................................................................................257
Flash.................................................................................................................257
........................................258
Common Object Request Broker Architecture(CORBA)........................................259
-..................................................................................264
11
-..................................................................................................268
Representational State Transfer (ReST)...............................................................269
..................................................................................................................270
...................................................................................................................270
14. - .............................................272
/......................................................................................272
..........................................................................................272
....................................................................273
................................................................................................274
.................................................................................................276
/ .....277
......................................................................................278
..............................................................................279
................................................................................................280
.................................................................................................281
/
............................................................................................................283
..................................................................................................................284
...................................................................................................................284
, ........................................................284
15. .....................................................................285
.................................................................286
// Smalltalk..................................................287
............................................................................289
...................................................................................289
......................................................................................294
..................................................................................296
.........................................................................................................297
..................................................................................................................299
...................................................................................................................299
, ........................................................299
,
,
(Matt Weisfeld) , . , .
, 20
.
.
- ,
, ,
developer.com, Dr. DobbsJournal, The C/C++ Users Journal, Software Development
Magazine, Java Report Project Management.
, . , ,
.
. , .
.
,
1998. Pearson, . , (Mark Taber),
(Songlin Qiu), (Barbara Hacha) (Seth Kerney),
.
(Jon Upchurch) ,
. .
(Donnie Santos)
, Objective-C.
,
, .
, vinitski@minsk.piter.com ( , ).
!
http://www.piter.com
.
, - . , , .
. ,
- , - , , - (XML),
Unified Modeling Language (UML),
- - ( ),
- , - ().
, : , -
. , , ,
, , .
, -
,
. - , , . .
,
- . - ,
. , -
C , C++
, -
. , UML, -
, . ,
-,
, - .
-
- .
16
, (Craig Larman)
What the UML Is and Isnt( UML ).
:
, UML, , UML-, ,
- . , , , .
, - UML- .
,
, -
. UML ,
, .
. , C ,
C++ , - . . , , C++,
C,
C++. , , C# .NET, VB .NET,
Objective-CJava, ,
- .
Visual Basic -. C
-, C++
. C++ C, -
C++. Objective-C ANSI C.
, -
, , , ,
- .
, , ,
- ,
- .
(, Objective-C, VB .NET, C++, C# .NET Java)
(, UML), .
C, 1980-
Smalltalk. , , ,
17
. , , -
(
, 1960-). , ,
, , , 1020% - .
, , , , ,
- .
, , , . ,
, ,
, - . 110 -
, 1115
- . , , 110 ( , ,
..), 1115
.
.
, :
,
, , -,
..;
Objective-C iOS;
XML JSON;
CSS, XSLT ..;
-, Simple Object Access
Protocol (SOAP), - RESTful ..;
/ ;
;
Java, C# .NET, VB .NET
Objective-C, .
, .
18
. ,
. , .
, , , ,
, .
,
- .
Java (Object-Oriented Design in Java) (Stephen Gilbert) (Bill McCarty).
, ,
, - .
- Java ,
.
, , C++ (Effective C++) (Scott Meyers),
- (Classical and Object-Oriented Software Engineering) . (Stephen
R. Schach), C++ (Thinking in C++) (Bruce Eckel),
UML. (UML Distilled) (Martin Fowler) Java (Java Design) (Peter Coad) (Mark
Mayfield).
-
,
, .
,
,
- ,
.
UML-,
UML ,
. ,
- ,
Java, C# .NET, VB .NET Objective-C UML-?
-, - .
-, - . , Java, C# .NET, VB .NET, Objective-C
19
,
UML, , .
, UML-
, , .
UML, . , UML-
.
, .
.
; , , , .
, Java, C# .NET,
VB .NET, Objective-C UML,
. , -
- , - - .
,
:
, , ;
,
.
-.
, , - .
,
.
1.
, - 1960-.
1990- - , , -
Smalltalk C++ .
-
.
, , ,
-.
, .
, . , .
, ,
, . , .
, ,
.
, ,
1990- /
/-, . ,
, . - . ,
, . , 20 .
, - .
21
, -
: , .
, , , -.
; , :
;
;
;
.
.
,
, , , .
, - .
? ( .)
, .
, , , . , , , , .
, ,
- . -
. , , ,
.
-
, , , -
. -
( ) ,
. , ,
, - . ,
.
: - ? , : , .
22
1. -
- . - ( )
.
, ? ,
. , ,
- , .
, ,
- ( ,
).
20
- , .
, ,
, , .
, ,
.
- , . , ( ) , . ,
, , ,
, .. 6.
. -
, . ,
- ,
, .
, ,
. , ,
, , , .
,
. -, ,
, , -.
23
-
,
- . , . ,
. , -, -. ,
-, .
-
- ,
: ? , . ,
.
, .
, - , .
: .
, , , ..
, , , ..
,
.
- . ,
. ,
.1.1, ,
. ,
.
.1.1.
24
1. -
-
-
, .
-
, , ,
, -,
. ,
. ,
, , , , .
- .
-
- ,
. .
, . -
, .
. -
.
.1.2,
, . ,
(
). -, ,
, .
.
, -
, . .
, .
.. C++
, ().
,
.
, , , , .
,
25
. , , ( , ). ,
. ,
Math myInt1
myInt2. , Math , myInt1 myInt2. sum()
.
.1.2.
- , . / .
(
), Math.
myInt1 myInt2 ,
, Math .
SOUND
- ,
. , -
,
.
, Sound (.5).
26
1. -
, , myObject
myInt1 myInt2? Math: myObject Math. .1.3 ,
.
sum Math. sum
myObject. , myObject , (, , ).
, , Math ,
myObject ( ,
). , , , ,
.
.1.3.
. .
, ,
.
, , ,
, .
myObject Math. myObject Math, . ,
( myObject myInt1 myInt2).
27
-
, ( )
, ,
.
-
,
- , .
, . ,
,
(.1.4) , , . ,
-
. ,
.
.1.4. ,
-
- , , (),
, . ,
, .
, - ,
. , .
.1.5 Employee .
, .
, ,
, . ,
, , .
28
1. -
.1.5. ,
- .
, - ,
.
, , .
, .
, , .
- . , .1.6,
, , , .. , (
). .
.1.6. Employee
, .
, . - -
29
, .
,
Employee
. ,
, setGender() getGender(). , ,
Employee gender.
, , ,
- ,
, . , . 11
12, - .
,
,
.
XML
,
. .NET-
.
, Name,
Java :
public String Name;
:
public void setName (String n) {name = n;};
public String getName() {return name;};
Name.
.
30
1. -
. ,
- 11 .
.
,
, . - .
, , . ,
:
;
, ;
.
.1.7.
.1.7. Employee
.1.7 , Payroll
calculatePay(),
. , Payroll
.
Employee (
getSocialSecurityNumber()). , , Payroll
getSocialSecurityNumber() Employee. Employee .
.1.8, ,
Employee/Payroll, .
31
UML-
, . ,
(, , ),
. 3.
: , () (). .1.8 ,
Employee socialSecurityNumber,
gender dateofBirth, ,
.
UML , .
Unified Modeling Language (UML).
, 10. UML- , . UML .
, ,
. , . , Employee,
Employee.
32
1. -
. ,
.1.9. Employee John ( )
,
Employee. Employee Mary . dateOfBirth
getDateOfBirth.
.1.9.
, . , .
/
. .
, .
,
33
.
?.
. ,
. , , -
( ),
.
- ,
?, ,
. . , ,
, .
. , (, )
(), ().
-
, ( Java, C#, Visual Basic .NET,
Objective C C++),
, Java ,
. , , C#.
, .
, .1.10. .
. , , ,
int float:
int x;
float y;
:
myClass myObject;
, myClass
, myObject .
, () ( ). , ,
. . ,
, .
,
34
1. -
(, ). ,
, .
.1.10.
, , Person:
public class Person{
//
private String name;
private String address;
//
public String getName(){
return name;
}
public void setName(String n){
name = n;
}
public String getAddress(){
return address;
}
public void setAddress(String adr){
address = adr;
}
}
35
, . , ,
. Person
, name address.
public,
. private,
. protected , 3.
, .
, ,
, .
, ( ) , . , . Person
getName(), setName(), getAddress() setAddress().
. , -
.
.
. ,
, .
. ,
.
:
public class Payroll{
String name;
Person p= new Person();
String = p.setName("Joe");
...
String = p.getName();
}
36
1. -
(, Payroll)
Payroll Person
getName(). - ,
. .
,
.
UML- . UML
, UML- .
. .1.11 Person,
.
.1.11. Person
, ( , ).
- , ,
.
,
. ( , , ) ,
. , , .
, , . .
37
, , ,
.
, ,
. .
, .
,
. .
, , ,
.
, . - ,
, public.
,
private. . . public .
, : . :
Square;
.
,
, (). ,
. , , , . ,
, . ,
,
( ).
, .
:
, , , . . ,
. .
38
1. -
. - . , public
.
Employee . ,
, , . , , , ,
, , . ,
, .
, , ,
(, , ),
.
/
.1.12 / , . . ,
, .
, ,
;
( ). , , .
,
.
, ,
.1.12.
.1.12.
39
/
Square. ,
. . ,
. , ; - . .1.13
. ,
(+) public, () private. ,
,
.
.1.13. IntSquare
:
public class IntSquare {
//
private int squareValue;
//
public int getSquare (int value) {
SquareValue =calculateSquare(value);
return squareValue;
}
//
private int calculateSquare (int value) {
return value*value;
}
}
, , , getSquare, .
calculateSquare. , SquareValue
40
1. -
, .
: ,
, , , .
, , . ,
Math.pow Java-, ,
, calculateSquare -
:
//
private int calculateSquare (int value) {
return = Math.pow(value,2);
}
, . , . , , , - .
- , , . : , , .
- ,
, ,
.
.
.
.
- . , Dog Cat, eyeColor. Dog, Cat
. - ,
, Mammal . Dog Cat
Mammal, .1.14.
41
.1.14.
, Mammal. , Dog
:
eyeColor
barkFrequency
// Mammal
// Dog
Dog :
getEyeColor
bark
// Mammal
// Dog
Dog Cat ,
, . ,
Dog , , Mammal.
, ( ),
, , . ,
Mammal , eyeColor hairColor, generateInternalHeat
growHair. , , ,
.
, , , ,
.
, ( ), . , Dog Cat
Mammal. Mammal , , Dog Cat.
. Cat Mammal
42
1. -
. Mammal, Cat , .
, , , Cat
, .
. Mammal Cat
, , ( ,
), . Cat
. ,
Cat, , .. ,
Cat, Dog , GermanShepherd Poodle (.1.15).
.
- (, Java, .NET Objective C) ,
. ,
C++, .
, .
.1.15. UML-
, GermanShepherd Poodle
Dog . ,
Dog, Mammal. , GermanShepherd Poodle
, Dog Mammal,
(.1.16).
43
.1.16.
, Circle, Square Star Shape. ,
, . ,
, . , Circle, Square
Star Shape.
.1.17 Draw Circle,
Star Square . Shape
, .
, , , Draw.
, ,
Draw, , .
, Circle, Star Square,
, . ,
.
.1.17. Shape
44
1. -
,
. ,
- .
, , . . ,
,
.
, , Shape Draw. - , :
? , ,
(, Draw() Shape
). . Circle. Shape
Draw, Circle Draw().
, ,
.
, Circle, Square Star.
Shape Draw
Shape, ,
Circle, Square Star .
, Draw ,
, . .
Shape:
public abstract class Shape{
private double area;
public abstract double getArea();
}
45
public Circle(double r) {
radius = r;
}
public double getArea() {
area = 3.14*(radius*radius);
return (area);
}
}
.
Circle Circle.
,
, .
, . , .
Circle , , radius Circle.
Circle getArea,
abstract Shape.
Rectangle:
public class Rectangle extends Shape{
double length;
double width;
public Rectangle(double l, double w){
length = l;
width = w;
}
public double getArea() {
area = length*width;
return (area);
}
}
,
.. getArea(). , Shape, Shape
getArea() . ,
,
(..1.18, UML-).
,
.
46
1. -
, Shape
:
Circle circle = new Circle(5);
Rectangle rectangle = new Rectangle(4,5);
, , ,
Shape:
stack.push(circle);
stack.push(rectangle);
?
,
. ,
. , ,
, . ,
( ). ,
( ).
. ,
, Shape ( , ):
while ( !stack.empty()) {
Shape shape = (Shape) stack.pop();
System.out.println (" = " + shape.getArea());
}
Shape:
shape.getArea()
47
, , .
, Circle , Rectangle . ( )
Shape , Shape .
, . , ,
. ,
Office, print(). print()
, . , ,
print(),
: ,
.
, .
. , . ,
.
, . , . ,
.
, .
, ,
. ,
: . ,
. . , ,
, , .
, .
. . ,
. , . , (
, ).
.
.
48
1. -
, , .
, , . , , ,
. ,
. , ,
, 7.
-
. .
.
- .
, , ,
, .
.
, .
. , -
. ,
.
, -. ,
(, Draw) ,
.
. , .
- , .
C# .NET. Java, .
TestPerson: C# .NET
using System;
namespace ConsoleApplication1
{
class TestPerson
49
,
{
static void Main(string[] args)
{
Person joe = new Person();
joe.Name = "joe";
Console.WriteLine(joe.Name);
Console.ReadLine();
}
}
public class Person
{
//
private String strName;
private String strAddress;
//
public String Name
{
get { return strName; }
set { strName = value; }
}
public String Address
{
get { return strAddress; }
set { strAddress = value; }
}
}
}
TestShape: C# .NET
using System;
namespace TestShape
{
class TestShape
{
public static void Main()
{
Circle circle = new Circle(5);
Console.WriteLine(circle.calcArea());
Rectangle rectangle = new Rectangle(4, 5);
50
1. -
Console.WriteLine(rectangle.calcArea());
Console.ReadLine();
}
}
public abstract class Shape
{
protected double area;
public abstract double calcArea();
}
public class Circle : Shape
{
private double radius;
public Circle(double r)
{
radius = r;
}
public override double calcArea()
{
area = 3.14 * (radius * radius);
return (area);
}
}
public class Rectangle : Shape
{
private double length;
private double width;
public Rectangle(double l, double w)
{
length = l;
width = w;
}
2.
1 - .
.
, , . . ,
, .
, - .
. , , ,
(- ).
. - , ,
.
.
-.
. ,
-. ,
.
,
.
,
, !
-
.
. , . , -
. .
, - . , - ,
52
2.
.
, - , , if .. , -
- .
FORTRAN COBOL C,
, COBOL C++, C# .NET,
Visual Basic .NET, Objective-C Java .
- .
- -
. ,
: - (, C++
- ),
- .
,
, - :
1,
.
1,
. ,
, ,
. , ,
,
.
(GUI Graphical User Interface).
, , ,
.
1? ,
, , -
53
(.2.1).
, . - , . , , ,
, , , .
.2.1.
.
, , ,
. ,
, , ,
, , .. , , , .
, .
, ,
. ,
, .
-
, , (
, ). ,
, , ( )
.
, .
,
. ,
, . ,
, , . , , ,
.
54
2.
. -
. . , - . , , , .
. ,
, ,
. ,
, ,
.
, , .
, . , , , .
- , . , ,
, . , ,
( )
.
,
, .
. , , , : . ,
. ,
. ,
.
, , .
, .
55
, .
, , : , , . ,
, , .
, .
, :
, . ,
, -.
,
, , .
:
,
, . :
. , ,
. , ,
.
/
( ) DataBaseReader. Java-, . ,
.
,
. ,
DataBaseReader. :
;
;
;
;
;
, ( );
;
;
.
, DataBaseReader, .
DataBaseReader ,
. ,
56
2.
, ,
(API Application Programming Interface), .
, ,
. ? , :
- ,
. , ,
. ,
, . ,
,
.
.2.2 ,
DataBaseReader.
, (,
, ,
). , ,
. , , , .
, ,
; , -
,
.
, , , , .
interface, Java
.NET. .
57
, .
.
, , ,
- ?
, ?
, ?
, ,
?
! -
.
, , . , , ,
.
, , ,
API- .
, ,
, . , ;
: , . . ,
, . ,
- .
, ,
. ,
. . -
- . :
.
- ,
?
-,
- . , - ,
, .
,
.
-, ,
, ,
58
2.
. . ,
-
, .
.
, . ,
, , .
, , .
- . . ,
.
- ,
( ) -
. -
, -
.
- . , , , , ,
, (, , ).
. .2.2 ,
, .
, , , , , ,
. , , , - . , , ,
. , .
(, Oracle)? open():
public void open(String Name){
/* */
/* API- Oracle */
/* */
};
59
, , ,
open String. Name, ,
, , Name
, . ,
.
!
, .
, Oracle
SQL Anywhere ( ).
, .
:
public void open(String Name){
/* */
/* API- SQL Anywhere */
/* */
};
,
. , , ,
! ,
, .
(
), , DataBaseReader.
,
. , , , Java .NET, .
, C++,
.
,
. .2.3 , .
- , .
60
2.
, ,
. ,
. , , ,
.
.2.3.
,
. , . ,
- . ,
, ,
.
, , . , ,
, , , ,
.., , .2.4,
.
, ,
, :
61
? : , ( , , , . , : ,
, ). , ,
, , , , ,
.2.5. ,
( -
,
).
.2.4.
? ,
? , ,
: , ,
, , ? , . ,
. . ,
- ,
, , - .
62
2.
.2.5.
,
. , .
, .
, .
, .
, , . .
- , , , . . ,
, , , .
. ,
. , .
, . -
63
,
.
, .
, , , ,
, , , .
, . , ( )
,
.
, , ,
,
.
, , ,
, . , , , .
. ,
,
. : ?
, . . , ,
, . , , ,
, , , . , , ,
, .
, , .
, ,
,
.
, , , , (,
). .2.6 , .
, , .
64
2.
.2.6.
, .
, . , , ,
. , , ,
. ,
UML.
,
- Java (ObjectOriented Design in Java) ,
. , . . ,
. ,
,
.
, ,
. ,
, .
1. .
2. , .
3. .
4. .
5. .
65
, , ?
1. , .
2. .
3. .
, , , . , , , ,
. .2.7 ,
Cabbie.
.2.7. Cabbie
, .
,
. , , , .
- ,
. ,
.
enterTaxi(), , , ,
. , . ,
, , .
, .
, ,
, , .
, , . , - ,
, ( ),
.
, .
,
66
2.
, , . ,
changePassword(); . changePassword().
.
, (
, , ).
, ,
, . , , , , .
, ,
. , .
,
- . , -
, - .
- ,
. , .
3 : ,
. ,
, . , DataBaseReader
, ,
. , , ,
.
3.
1 2 - .
, - ,
- ,
, .
,
- .
- ,
,
- .
, , ,
. - Java
C# , . Visual Basic .NET New, Objective-C
init. ,
.
Java-, .
, Cabbie, 2, :
public Cabbie(){
/* */
}
, ,
.
, Java- ( C# C++) . ,
.
68
3. -
, ,
, ,
:
public int Cabbie(){
/* */
}
,
, , .
.
:
Cabbie myCabbie = new Cabbie();
new Cabbie
. .
.
, new Cabbie() Cabbie
Cabbie, .
,
new. , ,
,
, , .
, Counter count,
count 0 :
count = 0;
, ( ),
. , .
,
.
, .
,
, . , .
, , , .
69
, Object
Java. , , Cabbie , :
public Cabbie(){
super();
}
-, , . .
, Cabbie ,
Object . ,
;
. , .
, . , ,
- .
, ,
- . , , -.
, ,
, ,
.
, . ,
,
. , ,
.
, .
. ,
. ,
Count:
public class Count {
int count;
public Count(){
count = 0;
}
}
70
3. -
, count
,
count 0, :
public Count(){
count = 0;
}
, ,
count :
public Count (int number){
count = number;
}
( , ). -
.
, .
(.3.1).
.3.1.
, :
public void getCab();
//
public void getCab (String cabbieName);
//
public void getCab (int numberOfPassengers);
, ,
. Java C# . , , :
public void getCab (String cabbieName);
public int getCab (String cabbieName);
71
,
.
, -
.
, ,
. , -
,
( ). ,
. -
.
UML
DataBaseReader, 2. , DataBaseReader.
.
, , ,
.
.3.2 DataBaseReader. ,
. , ,
. ,
DataBaseReader, .
.3.2. DataBaseReader
, .3.2
. , , .
72
3. -
, , , (.3.3).
.3.3.
73
, startPosition
. ,
, 0.
, . , , , . ,
. . , , .
new (.3.4).
1. . , .
, -.
2. .
( ),
( ).
DataBaseReader, , startPosition .
3. .
.3.4.
,
.
. , ,
74
3. -
! Java , .
, ,
- ,
0.
,
( ). , 0, ,
. ,
. 0 .
, ,
.
,
. , , . , , .
,
: Java
(Java Primer Plus) (Paul Tyma), (Gabriel
Torok) (Troy Downing) ,
, : , , ,
. - Java (ObjectOriented Design in Java)
, , .
!
.
,
.
(
).
.
, .
, ,
? ,
. ,
75
.
,
, .
, , , ,
.
,
. ,
,
, . , , .
,
.
, , .
, . .
, , :
if (a== 0)
a=1;
c= b/a;
, , ,
, ,
. 1,
. 1 , .
,
.
-
, , .
( )
. ,
,
( ) .
76
3. -
, .
, . ,
. ,
. ,
,
.
- , . , . , . Java, C#,
C++, Objective-CVisual Basic
catch throw. , ,
. ,
, .
Java- try/catch:
try {
//
} catch(Exception e) {
//
}
try catch.
, ,
.
1. try .
2. catch ,
catch (
try catch).
3. catch ,
try ( ,
, ,
).
4. catch (
), catch.
5. , try.
77
, . ,
Java:
try {
//
count = 0;
count = 5/count;
} catch(ArithmeticException e) {
//
System.out.println(e.getMessage());
count = 1;
}
System.out.println(" .");
. , .
, Java,
!
( count 0) try .
() try, , ,
(). , try,
catch ,
(
). catch , , ,
, , count 0.
catch, try/catch, Java
.
.3.5.
.3.5.
78
3. -
ArithmeticException catch, , ,
. ,
:
try {
//
} catch(Exception e) {
//
}
Exception catch ,
try.
, .
.
. . , ,
. ,
, , ,
, ,
.
, .
, . :
;
;
.
. :
public class Number {
public method1() {
79
int count;
}
public method2() {
}
}
80
3. -
, ,
. ,
, , , , .
. .3.6, ,
, .
:
public class Number {
int count;
// : method1 method2
public method1() {
count = 1;
}
public method2() {
count = 2;
}
}
.3.6.
, count
method1, method2.
81
. , count method1 method2 (
). ,
, , count .
count,
. count
.
Number:
Number number1 = new Number();
Number number2 = new Number();
Number number3 = new Number();
count. , method1() method2()
.
,
method1(), this C :
public method1() {
int count;
this.count = 1;
}
, :
this.count = 1;
this , , .
. this
count, .
82
3. -
this .
, . Java, C#, C++ Objective-C
:
public class Number {
static int count;
public method1() {
}
}
- count ,
. ,
count. , ,
(.3.7). ,
- .
.3.7.
;
.
Count:
83
Count Count1 = new Count();
Count Count2 = new Count();
, Count1 ,
count . , Count2 count . , Count2
, , Count1, .
- . C++. . , , ,
. :
X= 5 + 6;
, X 11. .
- . , , :
String firstName = "Joe", lastName = "Smith";
String Name = firstName + " " + lastName;
, .
? :
Matrix a, b, c;
c= a+ b;
, ,
.
.
, .
. , ,
. ? . , ,
,
X, 1:
x= 5 + 6;
84
3. -
- ,
Java, .NET Objective-C, .
, ,
. , Java, , , , .
C++, , ,
, .
7.
, ,
.
, . .
, ?
.
. . , .
- , C++.
,
. , .
.
,
.
, , Java, .NET
Objective-C, , -
, . -
Java, .NET Objective-C ; ,
.
,
. ,
,
, ,
. 8.
85
,
. ,
, .
. C++ (Effective C++) .
,
. , , . ,
, , ,
.
. ,
, .
. -
, . ,
,
( ).
?
, ,
, .
.
, , , , .
. , , -
Java (Object-Oriented Design in Java).
.3.8, ,
( ), . ,
( ) () . ,
,
.
.
, , .
86
3. -
,
, .
. , , .
, , .
.3.8.
-
, , , - , - ,
, , . 4 , .
87
,
, . Java (Java
Primer Plus). : The Waite Group, 1996.
C# .NET. Java, .
TestNumber: C# .NET
using System;
namespace TestNumber
{
class Program
{
public static void Main()
{
Number number1 = new Number();
Number number2 = new Number();
Number number3 = new Number();
}
}
public class Number
{
int count = 0; // : method1 method2
public void method1()
{
count = 1;
}
public void method2()
{
count = 2;
}
}
}
4.
-
. ,
, ,
, ,
. , ,
, . .
.
, . ,
, . , 2.
.
, ,
.
. ( ) , .
.
, . ,
, . ,
, .
, . , Java . ,
.
89
.4.1 , . ,
, Cabbie
class:
public class Cabbie {
}
.4.1. ,
90
4.
JAVA-
, Java-. - ,
C#, .NET, VB .NET, Objective-C
C++ - , Smalltalk.
Cabbie
.
. Java, C# .NET, Objective-CC++
.
JAVA C#
Java C# . Java (/***/)
, . . C#
XML-.
C /* (, )
*/ (, ) .
, .
(*/), -
.
, Cabbie:
/*
Cabbie Cab
*/
// (, ).
, , . ,
.
, Cabbie:
// name, Cabbie
, . Cabbie
91
: private static.
private ,
.
. , , .
, (
).
static , ,
,
. (.3, ). , Cabbie
500,
companyName (.4.2).
.4.2.
name , Cabbie:
private String name;
92
4.
,
. .
myCab . Cab
:
private Cab myCab;
Cab . ,
Cabbie. Cab
Cabbie. Cab.
, Cab;
.
Cabbie . , ,
, , Cabbie.
:
public Cabbie() {
name = null;
myCab = null;
}
, . , , .
, ,
.
, . ,
, ,
.
name myCab null:
name = null;
myCab = null;
NULL
null .
, null .
null , . -
93
, , . , null , .
null ( ), ,
. , null String.
, .NET name = string.empty;.
,
. , null .
, . , myCab , , ,
, . myCab null , , , ,
- null. ,
,
.
: Employee,
spouse (, ),
, .
null,
.
name myCab:
public Cabbie(String iName, String serialNumber) {
name = iName;
myCab = new Cab(serialNumber);
}
, .
, myCab:
myCab = new Cab(serialNumber);
Cab
. .4.3 , Cab myCab. . ,
public. , ,
. ,
Cab.
94
4.
, , ,
private, - . , , ,
. ?
, , . ,
;
.
. , ,
, .
,
.
, Cab . , name. - ,
. name public
,
, name .
Cabbie name,
Cabbie. , .
, get() set().
set get, :
// name, Cabbie
public void setName(String iName) {
name = iName;
}
// name, Cabbie
95
public String getName() {
return name;
}
Supervisor
Cabbie name (.4.4). ,
Supervisor ;
Cabbie. . ,
setAge(), ,
0 .
0, setAge() .
.
.4.4.
. ,
: ,
. ,
. .
, getCompanyName static,
; 3. ,
companyName static. , ,
static ,
.
,
. . ,
.
,
.4.5 , .
96
4.
// name, Cabbie
public static String getCompanyName() {
return companyName;
}
, , , , . , .
.4.5.
, public . .
. 2, , .
giveDestination,
, :
public void giveDestination (){
}
, . ,
.
97
, ,
public, .
private:
private void turnRight(){
}
private void turnLeft() {
}
,
. ,
, . :
, , , giveDestination:
public void giveDestination (){
...
turnRight();
turnLeft();
...
}
,
, , . , .
, .
, .
, 5
.
98
4.
. -
Java (Object-Oriented Design in Java). : The Waite Group Press
(Pearson Education), 1998.
, . Java (Java
Primer Plus). : The Waite Group, 1996.
C# .NET. Java, .
TestCab: C# .NET
using System;
namespace ConsoleApplication1
{
class TestPerson
{
public static void Main()
{
Cabbie joe = new Cabbie("Joe", "1234");
Console.WriteLine(joe.Name);
Console.ReadLine();
}
}
public class Cabbie
{
private string _Name;
private Cab _Cab;
public Cabbie() {
_Name = null;
_Cab = null;
}
public Cabbie(string name, string serialNumber) {
_Name = name;
_Cab = new Cab(serialNumber);
}
//
99
,
public String Name
{
get { return _Name; }
set { _Name = value; }
}
}
public class Cab
{
public Cab (string serialNumber) {
SerialNumber = serialNumber;
}
// get, set
public string SerialNumber { get; private set; }
}
}
5.
, -
,
. ,
, .
. , . , ,
,
.
- ,
. -
. , , ,
, -
, .
, . ,
.
, , , , .
, . Cabbie .
Cab Cabbie . .5.1, Cab Cabbie , .
-
- .
, , .
, , .
101
, , , C++: 50 (Effective
C++: 50 Specific Ways to Improve Your Programs and Designs).
.
, C++
, , , C++
C, C++ - . ,
. , , - , , C++.
, - .
, , , C++
Objective-C, Java .NET.
, , , . - . -
Java (Object-Oriented Design in Java) ,
, . ,
.
. , ,
102 5.
. (
), .
( ,
),
, ,
.
, , , ,
. ,
, .
,
. ,
,
.
, Cabbie.
name Cabbie, Cabbie
;
getName(). , Supervisor
name Cabbie, getName() Cabbie.
Supervisor Cabbie name (.5.2).
.5.2. ,
.
, . ,
, .
.
,
, . -
103
(,, )
, ,
.
, , . ,
.
, ,
.
, .
, , . , , .
Cabbie ,
, . Supervisor ,
, Cabbie, . ,
Cabbie
(.5.3). , , .
, .
.5.3.
(,, )
, .
3. ,
.
,
. ,
. , . ,
.
104 5.
, ,
, . , - . Java .NET
. C++
, .
, .
,
,
, , . , , , ,
. , ,
. -
, .
, , ,
- .
.
, ,
. 3.
, .
. ( , ) , .
.
, -
, .
, , , . , ,
, .
,
, .
105
.
, . ,
- /
( ),
.
. , - , . , Java .NET,
. 4, .
, .
/ . ,
, ,
.
, . ,
. .
,
. ,
.
Cabbie Supervisor
; (.5.4).
.5.4.
106 5.
, ,
.
,
. , Cabbie , , .
, .
.
, Cabbie , .
, .
,
, . .
. Person,
, , , Employee
Vendor. , Employee Person;
Person . Person , ,
, Employee Vendor
(, ,
Person). ,
Employee , .
, , , Employee, .
,
. Person , .
.
?
, static.
3, static.
, ,
.
.
,
107
. , ,
, , . , , , , , . -
, , , ,
.
, .
, . , , . , . ,
, .
,
, .
,
() ( ,
),
.
(
). , ,
- . - , .
(.5.5).
.5.5.
108 5.
, , , .
, , , .
-,
. - ,
.
3 . ,
. , , . , , , ,
.
. ,
, . ,
, .
, - .
, .
- .
, .
, , ,
. :
public class Math {
int temp=0;
public int swap (int a, int b) {
temp = a;
a=b;
b=temp;
109
return temp;
}
}
? , ,
temp swap().
, . , temp swap():
public class Math {
public int swap (int a, int b) {
int temp=0;
temp = a;
a=b;
b=temp;
return temp;
}
}
Java
(Java Primer Plus) , , .
.
, . print
circle, (.5.6):
print(circle);
print, draw . ( -
if/else) , ,
. :
printCircle(circle);
printSquare(square);
case :
110 5.
switch (shape) {
case 1: printCircle(circle); break;
case 2: printSquare(square); break;
case 3: printTriangle(triangle); break;
default: System.out.println(" .");break;
}
.5.6. - ,
print
- .
Circle , Shape , , , (.5.7).
shape.print(); //
shape.print(); //
, ; .
.5.7. - ,
print
111
. ,
, .
.
, ( ).
,
, , .
, , . , , , ,
. , , .
(Scott Ambler) -
(The Object Primer).
, . .
, .
, getName() Cabbie,
, , . , .
,
.
,
.
. , !
, .
, . , ,
. . , , .
,
,
, .
112 5.
(
- Java (Object-Oriented Design in
Java). ,
.
,
( ,
). , . ,
, , .
.5.8: DataBaseReader, ,
, ,
( , , ).
, ,
, .
.5.8.
, ( ):
public class DataBaseReader {
private String db[] = { "Record1",
"Record2",
113
"Record3",
"Record4",
"Record5"};
private boolean DBOpen = false;
private int pos;
public void open(String Name){
DBOpen = true;
}
public void close(){
DBOpen = false;
}
public void goToFirst(){
pos = 0;
}
public void goToLast(){
pos = 4;
}
public int howManyRecords(){
int numOfRecords = 5;
return numOfRecords;
}
public String getRecord(int key){
/* */
return db[key];
}
public String getNextRecord(){
/* */
return db[pos++];
}
}
, .
, .
,
.
, . ,
. ,
,
. , !
, , .
114 5.
,
- .
. , -.
, -
.
, , . , , .
,
.
XML. , , -
. .
, . .
- ,
,
,
-.
. ,
. , .
.
(, ) ( ), , . . .
, .
,
. -
115
. , ,
, .
Java Serializable,
.
C# .NET Visual Basic .NET ISerializable, Microsoft :
. , , . C# .NET, Visual
Basic .NET, :
' Visual Basic .NET
Public Interface ISerializable
// C# .NET
public interface ISerializable
,
. XML, , .
,
. .
, , , .
. , .
. , , .
. 6 .
. - (The Object
Primer). 3-. : Cambridge University Press, 2004.
. -
Java (Object-Oriented Design in Java). : The Waite Group Press
(Pearson Education), 1998.
116 5.
, . Java (Java
Primer Plus). : The Waite Group, 1996.
. Java 1.1 (Java 1.1 Developers
Guide). : Sams Publishing, 1997.
C# .NET. Java, .
TestMath: C# .NET
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
namespace TestMath
{
public class Math
{
public int swap(int a, int b)
{
int temp = 0;
temp = a;
a= b;
b= temp;
return temp;
}
}
class TestMath
{
public static void Main()
{
Math myMath = new Math();
myMath.swap(2, 3);
}
}
}
6.
,
, . ,
. ,
,
.
-
. , - , ,
,
. , , .
,
.
5 ,
.
, .
,
, , , ,
- . , , ,
, . .
, .
, , . . , . ,
, , . ,
118 6.
.
- , . , , . , .
, -
, . , , .
, -
.
1. .
2. , .
3. , .
4. .
5. .
6. .
7. , .
8. , ,
.
- .
.
. , .
Unified Modeling Language (UML). , UML
, .
UML. , .
, . ,
.
, , ,
.
, . , ,
. , , ,
119
.. . , , , , Scrum .,
.
. ,
.
. , .
,
(.6.1).
.6.1.
,
.
- / .
- .
- ,
.
, . ,
120 6.
--
- , , . , ,
, , , ,
.
, , . .
. , , , ,
.
. , , , . ,
, , . ,
.
, ? ,
. , . , ,
.
, -,
, ,
, . , ,
, , .
.
, ,
,
. ,
,
. ,
, ,
.
, .
(.6.2).
121
.6.2.
. , .
.
. ,
, , .
, .
, , .
,
, .
, ( ,
), .
- .
.
, . , . , .
122 6.
, , , .
, .
,
. , , , .
, , ,
, ,
.
, , ,
. ,
,
.
,
.
(
),
.
.
. .
. ,
, .
.
,
, .
, . ,
, .
,
.
. Visual Basic .NET
,
. , -
(,
) , .
.
.
123
,
. ,
. ,
. ,
. , ,
. . , .
,
, ,
.
.
, , , . , Employee
.
, .
. ,
, . . ,
, -
.
, ,
,
. ,
.
UML. , UML
UML.
,
.
. ,
124 6.
.
-
Java, . .
Visual Basic, . ,
.
,
.
,
, - , , . , ,
: -
? : !
, . , -
- , .
.
, , ,
.
, .
,
. , ,
,
, , COBOL, C.. , ,
, , - .
.
: -
? , . ,
.
125
,
, , Java. , Java-, ,
, .
; ,
, ,
, . , ,
, ,
.
,
, - , , . , ,
, .
,
. , if .
Java-, 0
, , 5:
class MainApplication {
public static void main(String args[]) {
int x= 0;
while (x<= 10) {
if (x==5) System.out.println("x= " + x);
x++;
}
}
}
- , , , .
: ,
.
126 6.
, , , :
int x= 0;
, :
while (x<= 10) {
. , : , , .
if:
if (x==5)
, :
while (x<= 10) {
}
- while :
(x<= 10)
,
.
, -.
(, , ),
-
.
(, ), .
.
.6.3. , , ,
, , ,
.
, , . add, :
class SomeMath {
public int add(int a, int b) {
return a+ b;
}
}
127
.6.3.
, ,
(a+b), add. , ,
. , ,
, :
public class TestMath {
public static void main(String[] args) {
int x= 0;
SomeMath math = new SomeMath();
x= math.add(1,2);
System.out.println("x= " + x);
}
}
, , . ,
. :
public static int fib(int n) {
if (n< 2) {
return n;
128 6.
} else {
return fib(n-1)+fib(n-2);
}
}
, -
, ( ) ,
fib , .. , ,
.
(
) . , , ,
, ,
( ),
,
.
, , . Windows
:
System.out.println("\007");
( ),
Sound, beep, :
class Sound {
public void beep() {
System.out.println("\007");
}
}
, ,
beep:
public class TestBeep {
public static void main(String[] args) {
Sound mySound = new Sound();
mySound.beep();
}
}
. ,
,
129
. , , , Windows, . ,
, Sound, . , , , -
beep.
(-)
,
. , ,
(-) .
,
- . , . ,
. , - , , ,
.. .
, , , ,
. ,
, - ,
.
? , ,
.
, 2.
, . , ,
(..2.3).
, ,
.
. , ,
. , SQL-
,
.
. - . 12.
, / ,
2 (..2.1). ()
: , ,
, .
130 6.
, , . .
. , -
. , . ,
.
, () - ()
() .
,
.
. 7 ,
, .
. - (The Object
Primer). 3-. : Cambridge University Press, 2004.
. :
(Code Complete: APractical Handbook of Software
Construction). 2-. : Microsoft Press, 2004.
. -
Java (Object-Oriented Design in Java). : The Waite Group Press
(Pearson Education), 1998.
- ., . . -
(Designing Object-Oriented Software).
--: Prentice-Hall, 1997.
7.
.
.
, - . , .
- (
,
-), .
,
. , ,
.
/
. ( )
( ).
, ,
.
. ,
.
, . , (
), .
.
,
1. , .
, .
/ .
. . , . , .
132 7.
, (
) , . , ; , .
, .
-
, ,
- .
,
- .
.
. Java (Java Design)
.
- . Visual Basic Visual Basic .NET, . COM Microsoft
( 8).
-
. , ,
,
Objective-C. ,
, .
, , , , . , . , ,
, .
, ,
.
. ,
,
,
- .
, .
, ,
- , . , , . , ,
.
133
1 ,
. ,
, .
, ,
: , B ,
, .
- ,
.
,
1. Dog. ,
, Dog Cat.
Dog: bark pant. ,
Dog, (.7.1).
.7.1. Dog
, GoldenRetriever.
, ,
Dog. : GoldenRetriever Dog.
Dog
GoldenRetriever (.7.2).
134 7.
GoldenRetriever ,
Dog. .
-, GoldenRetriever,
, , bark pant. , ,
. bark pant
, , Dog, .
..
, Dog. LhasaApso.
,
, .
; , - ,
. , LhasaApso, Dog , GoldenRetriever
(.7.3).
GoldenRetriever bark pant ,
Dog. . ,
, , . ,
, GoldenRetriever ,
. .
.
.
, bark()
pant() . ,
bark(). Dog,
LhasaApso GoldenRetriever.
135
? ,
. ,
, , Dog?
C++ (Effective C++)
, . Bird.
, , . ,
Bird, fly.
. ?
, .
, - fly.
fly , ,
, .
. ,
fly,
. fly , , ,
fly, . , fly , .
. , , -
.
Dog ,
bark, . . ,
. , .
, ?
? .7.4 ,
Dog.
Dog .
Dog
. , -,
. , ,
.
. Dog,
. GoldenRetriever, LhasaApso Basenji . ,
, .
Dog, ,
, , , - ,
136 7.
. , . ,
, . ,
bark BarkingDog. yodels
YodelingDog. , -
. Dog ,
BarkingDog YodelingDog. Basenji
YodelingDog , LhasaApso GoldenRetriever
BarkingDog.
.7.4. Dog
BarkingDog YodelingDog.
bark yodels
, , , .
, . ,
bark yodels ,
8.
. ,
, , ,
.
, . ,
. , : ,
137
? ,
,
.
, .
,
.
,
. ,
, . ,
, , ,
. , , , ,
. ,
.
.
, ,
, .
, ,
, , .
,
.
,
-
. ,
Dog,
(.7.5)?
, , , , Canine, , .
, .
138 7.
.7.5. Canine
.
, , , , ,
- . , .
, . , , bark() , yodels(),
, , , , bark().
, . . ,
. , -
. ,
. ,
. , , , .
. ,
,
. , ,
. , , - .
139
,
. , , (.7.6). ,
, ,
, .
.7.6.
,
,
. 9 , . , .
UML. UML ,
, ,
.7.7.
, UML
UML , , . (
), ,
.
.7.7. UML
140 7.
, , Car
SteeringWheel, Car. , Car
( ) SteeringWheel.
. ,
. , . ,
,
.
, .
, , .
?
, .
, . , . .
. 9.
, (, ) .
, , , ,
. -
, , , . ,
,
, .
. 7.8 Car, Engine, Stereo
Door.
, , Car,
. Engine Pistons SparkPlugs ; Stereo Radio
Cassette; Door Handle. , :
Radio Tuner. , Handle Lock,
Cassette FastForwardButton. ,
Tuner Dial.
, .
,
,
.
, ,
, , ,
, .
141
.7.8. Car
-
- .
/ . , ,
. .
, , .
. .
?
- . -
, . - . !
142 7.
? -
? .
,
. ,
.
,
, , .
:
, .
, , , .
. ,
, ,
. , .
6 , .
, Cabbie (.7.9)
, Cabbie
.
, , . , ?
Cabbie, , .
,
Cabbie, , .
143
Cabbie PartTimeCabbie, Cabbie, Cabbie
.
, , UML-, .7.10. Part
TimeCabbie Cabbie. PartTimeCabbie
Cabbie, giveDirections(). giveDirections()
Cabbie, PartTimeCabbie
, Cabbie.
Cabbie Cabbie.
, ,
.
,
, ,
. ,
: Circle Shape,
Shape Circle, Circle Shape.
? , . , , (Window), Rectangle:
public class Rectangle {
}
144 7.
public class Window extends Rectangle {
}
Window
, Rectangle.
Rectangle, , , Square. Window
Rectangle ( Rectangle); Rectangle. Window Rectangle,
Rectangle:
public class Window {
Rectangle menubar;
Rectangle statusbar;
Rectangle mainview;
}
-
.
- .
. , .
.
1, . ,
.
. ,
,
.
1, Shape.
Draw. - ,
, , , : ?
(,
Draw Shape ). ,
.
Circle . Shape Draw, Circle
Draw. ,
, .
Shape 1 (.7.11).
. , Shape . ,
145
getArea(). 8
.
.7.11. Shape
Rectangle Circle ,
. Rectangle Circle , - . , . . , Shape.
. , ,
. ,
getArea() Circle, , , ,
getArea() Rectangle. , Circle Rectangle
. Circle
, , . , Circle
, . Shape ,
, . , UML- (..7.11)
getArea() Shape . ,
.
, : Shape Circle, Rectangle Star. :
public abstract class Shape{
public abstract void draw();
}
public class Circle extends Shape{
146 7.
public void draw() {
System.out.println(" ");
}
}
public class Rectangle extends Shape{
public void draw() {
System.out.println(" ");
}
}
public class Star extends Shape{
public void draw() {
System.out.println(" ");
}
}
, draw().
, : . Shape
; Circle, Rectangle Star
. :
public class TestShape {
public static void main(String args[]) {
Circle circle = new Circle();
Rectangle rectangle = new Rectangle();
Star star = new Star();
circle.draw();
rectangle.draw();
star.draw();
}
}
147
circle.draw();
rectangle.draw();
star.draw();
TestShape, :
C:\>java TestShape
. ,
, Triangle? ,
, . Shape
, :
public class Triangle extends Shape{
public void draw() {
System.out.println(" ");
}
}
Triangle. Shape ,
, Triangle , :
public class TestShape {
public static void main(String args[]) {
Circle circle = new Circle();
Rectangle rectangle = new Rectangle();
Star star = new Star();
Triangle triangle = new Triangle ();
circle.draw();
rectangle.draw();
star.draw();
triangle.draw();
}
}
C:\>java TestShape
148 7.
, Shape
, , .
, ,
:
public class TestShape {
public static void main(String args[]) {
Circle circle = new Circle();
Rectangle rectangle = new Rectangle();
Star star = new Star();
drawMe(circle);
drawMe(rectangle);
drawMe(star);
}
static void drawMe(Shape s) {
s.draw();
}
}
Shape drawMe(),
,
. TestShape ,
.
149
C++ , :
class Shape
{
public:
virtual void draw() = 0;
}
, Objective-C
.
, Java-
Shape:
public abstract class Shape{
public abstract void draw();
}
Objective-C .
, , Java, Objective-C,
draw():
@protocol Shape
@required
- (void) draw;
@end // Shape
, Java-
Objective-C. Java-:
public abstract class Shape{
public abstract void draw();
public void print() {
System.out.println(" ");
}
}
, Java, print()
, .
C# .NET, VB .NET C++,
Objective-C, :
@protocol Shape
@required
- (void) draw;
150 7.
- (void) print;
@end // Shape
print(), ; . , - , , ,
.
,
. , - , ,
, ,
.
. ,
, ,
, ,
, . , , ,
. , ,
.
Java-
. 8 , , Java- .
. Objective-C
(Visual Quickstart Guide, Objective-C). : Peachpit Press, 2010.
, ., ., .,
. -
(Object-Oriented Analysis and Design with Applications).
3-. : Addison-Wesley, 2007.
. -
Java (Object-Oriented Design in Java). : The Waite Group Press
(Pearson Education), 1998.
151
,
C# .NET. Java-,
.
using System;
namespace TestShape
{
public class TestShape
{
public static void Main()
{
Circle circle = new Circle();
Rectangle rectangle = new Rectangle();
circle.draw();
rectangle.draw();
}
}
public abstract class Shape
{
public abstract void draw();
}
public class Circle : Shape
{
public override void draw()
{
Console.WriteLine(" ");
}
}
public class Rectangle : Shape
{
public override void draw()
{
152 7.
Console.WriteLine(" ");
}
}
public class Star : Shape
{
public override void draw()
{
Console.WriteLine(" ");
}
}
public class Triangle : Shape
{
public override void draw()
{
Console.WriteLine(" ");
}
}
}
8.
:
7 ,
- .
Java-,
Objective-C .
, , ,
. ,
, , , , ( ,
Objective-C).
, .
: ?
, .
. , , . .
, - ,
, ,
.
. , , , .
-
. , -
154 8.
, -. , ,
COBOL, C VB, .
, , - , . - , .
.
, .
, .
, . . . , (Microsoft
Word 2010), , .
, (Microsoft PowerPoint 2010)
(Microsoft Excel 2010),
. ( ,
) . , ,
(, , ..).
,
. , . , , ,
.
, , .
, Microsoft Windows,
. Windows
,
, . : , /. , .
. .8.1
Microsoft Word. , , .
155
.8.1.
, ,
, , , , , ..
,
. , . -, ,
. -,
,
(, ,
).
, ?
, , ,
,
.
7 , , .
.
: , , ? : ,
.
? , , .
, , , ,
156 8.
( , ).
(API Application
Programming Interface).
, , Java,
API- JMenuBar , . .8.2 Java API.
API-, Java, . , Java.
.8.2. API-
,
API. , API- . Dictionary.com (http://www.dictionary.com)
, , .
, API-, , .
157
, .
, .. ( ..). ,
.
, . ,
.
,
, .
-, , .
, . , Java .NET,
.
. , ,
- . ,
Shape. ,
. - ,
, , , : ?
, . -
,
, . ,
. , ,
. ? ,
.
, , ,
. , .
-, ,
. , , , ,
draw(). , ,
draw(), ,
. , ,
.
158 8.
-, , . ,
,
draw(), . ,
Circle Rectangle draw(), , Circle , Rectangle,
, .
Circle Rectangle,
Shape, Draw (.8.3).
.8.3.
, , - . Draw , , .
Draw Circle , Draw
Rectangle . , ,
. :
circle.draw();
rectangle.draw();
//
//
, , Rectangle Circle
Shape. Shape:
public abstract class Shape {
public abstract void draw();
//
, -
draw(); , draw() (
).
. -, Shape , , draw(), .
159
. , Shape
, , ,
( case).
. ,
- .
-, , .
Circle Rectangle:
public class Circle extends Shape {
public void Draw() {System.out.println (" ")};
}
public class Rectangle extends Shape {
public void Draw() {System.out.println (" ")};
}
,
Shape (, ,
, ,
). , Circle Rectangle -
draw(), . , Shape color
. setColor() Circle Rectangle. ,
, , .
.
160 8.
, Shape, Circle Rectangle
, , . Circle Shape , Rectangle. ,
.
, , C++ . C++, , , ,
. , C++ .
, . , .
class Shape
{
public:
virtual void draw() = 0;
}
,
, ,
. , .
: (GUI Graphical User Interface) ,
, .
: , , .
: Objective-C , .
: Java- Objective-C
.
: , , Java .NET
, ? Objective-C ?
161
, C++ ,
Java, Objective-C.NET. Java, Objective-C.NET
,
. ; , Java .NET
. ,
, . , , , .
,
. .
, , ,
, .
,
.
- , UML . Nameable, .8.4.
, Nameable UML- ,
( ).
, : getName() setName(). :
public interface Nameable {
String getName();
void setName (String aName);
}
Objective-C:
@protocol Nameable
@required
162 8.
- (char *) getName;
- (void) setName: (char *) n;
@end // Nameable
, ,
? ,
,
. ?
, , ,
, . Mammal.
public abstract class Mammal {
public void generateHeat() {System.out.println(" ");}
public abstract void makeNoise();
}
generateHeat()
makeNoise(). , . ,
.
Head, ,
:
public class Head {
String size;
public String getSize() {
return size;
}
163
public void setSize(String aSize) { size = aSize;}
}
.8.5. UML-
, Java .NET , . ,
.8.5 . , .
? ? ?
.
:
Dog Mammal, ;
164 8.
Dog Nameable, ;
Dog Head, .
,
:
public class Dog extends Mammal implements Nameable {
String name;
Head head;
public void makeNoise(){System.out.println("");}
public void setName (String aName) {name = aName;}
public String getName () {return (name);}
}
UML-, :
Dog Nameable ,
? . , ,
. - .
, . .
.
.
, Reptile Mammal.
.
.
.
, . , Dog Mammal. .
,
.
,
. , . .
. , Mammal generateHeat().
, , , . . -
. , ,
165
, , .
, , ..
,
,
? Java (
C# VB) . :
Dog D= new Dog();
Head H= D;
, :
Test.java:6: . Dog
Head. Head H= D;
, Dog Head. , . ,
, :
Dog D= new Dog();
Mammal M= D;
, ,
, Dog Mammal.
- .
? , :
Dog D= new Dog();
Nameable N= D;
. , ,
Dog , . ,
, ,
.
NAMEABLE
, .
Nameable, ,
getName() setName(). , .
, , .
, .
, ,
.
166 8.
, . ,
, , .
: Planet, Car Dog.
. ,
, . Planet:
public class Planet {
String planetName;
public void getplanetName() {return planetName;};
}
Car :
public class Car {
String carName;
public String getCarName() { return carName;};
}
Dog :
public class Dog {
String dogName;
public String getDogName() { return dogName;};
}
, , ,
( !) , ,
. , , ,
, ( ),
.
Nameable.
, ,
, .
,
. Planet, Car Dog
.
, (
Nameable ,
). ,
167
Nameable. , ,
:
public interface Nameable {
public String getName();
public void setName(String aName);
}
, , .
,
. .
, , , .
, , -
(,
)? ,
, .
168 8.
, , , , ,
. ,
.
, . ,
. , ,
Java- Runnable. Java- Runnable,
,
run(). , , , run(),
Runnable. run() ,
.
. ,
, . ,
, . , ;
.
Nameable, . ,
.
,
.
, , , .
. , ,
, ,
.
,
, , . ( ) . ,
, , , , , .
169
-. ,
PapasPizza.
, ,
. ,
, , PapasPizza, .
, , ,
, , .
, . , 15:00
(, ),
18:00. ,
(, , ). , , , . , , .
, 18:00.
, .
. , ,
, ,
,
.
,
. PapasPizza
.
, PapasPizza,
DadsDonuts, .
PapasPizza DadsDonuts ,
. DadsDonuts
- .
, , .
, ,
?
, PapasPizza DadsDonuts,
,
? ,
, -,
, . ,
: , .
, .
170 8.
-,
. -, ,
, , ,
.
, . ,
.
, . , , .
. , , ,
,
, .
, , , UML .8.6.
.8.6. ,
testDonutShop testPizzaShop
. , .
- . . -, , , .
. , , .. .
.
171
, , , , , , - , ,
. ,
, , . ,
.
, , PapasPizza .
,
. , , , .
PapasPizza. 2.01papa.
, , DadsDonuts , .
, PapasPizza , ,
DadsDonuts. , PapasPizza , DadsDonuts . , , PapasPizza,
DadsDonuts, .
PapasPizza , . , - ,
,
2.03dad.
, .
.
. , . , (,
, ).
, ,
. ,
, , PapasPizza
DadsDonuts .
, , . ,
, .
. -, -.
testPizzaShop
testDonutShop, , Shop,
.
172 8.
, testPizzaShop testDonutShop
getInventory() buyInventory().
, , Shop, getInventory() buyInventory(). .
, . Java . , .
, .
, ( Nameable) .
-
:
Nameable, ;
Shop, ;
CustList, ;
Shop ,
.
UML
Shop .
.8.7: getInventory() buyInventory()
DonutShop PizzaShop Shop.
, , Shop,
Shop (, GroceryShop). Shop ,
:
public abstract class Shop {
CustList customerList;
public void CalculateSaleTax() {
System.out.println(" ");
}
public abstract String[] getInventory();
public abstract void buyInventory(String item);
}
173
, Nameable:
public interface Nameable {
public abstract String getName();
public abstract void setName(String name);
}
,
() . . , . DonutShop:
public class DonutShop extends Shop implements Nameable {
String companyName;
174 8.
String[] menuItems = {
"",
"",
" ",
"",
""
}
public String[] getInventory() {
return menuItems;
}
public void buyInventory(String item) {
System.out.println("\n " + item);
}
public String getName(){
return companyName;
}
public void setName(String name){
companyName = name;
}
}
PizzaShop :
public class PizzaShop extends Shop implements Nameable {
String companyName;
String[] foodOfferings = {
"",
"",
" ",
"",
""
}
public String[] getInventory() {
return foodOfferings;
}
175
public void buyInventory(String item) {
System.out.println("\n " + item);
}
public String getName(){
return companyName;
}
public void setName(String name){
companyName = name;
}
}
,
,
(Shop) (PizzaShop, DonutShop). - .
(Shop). , Shop getInventory() buyInventory().
getName() setName() ,
Nameable.
,
, . .
Shop. Shop,
, , :
DonutShop myShop= new DonutShop();
PizzaShop myShop = new PizzaShop ();
?
. Java, :
String className = args[0];
Shop myShop;
myShop = (Shop)Class.forName(className).newInstance();
className ( className, ).
176 8.
Shop ( , ,
).
class TestShop {
public static void main (String args[]) {
Shop shop = null;
String className = args[0];
System.out.println(" :" + className + "\n");
try {
// new pizzaShop();
shop = (Shop)Class.forName(className).newInstance();
} catch (Exception e) {
}
e.printStackTrace();
,
PizzaShop, DonutShop. GroceryShop,
. .
,
.
, . ,
.
177
,
9 - , , ,
.
. Objective-C
(Visual Quickstart Guide, Objective-C). : Peachpit Press, 2010.
, ., ., .,
. - (Object-Oriented Analysis and Design with Applications).
3-. : Addison-Wesley, 2007.
. C++ (Effective C++). 3-.
: Addison-Wesley Professional, 2005.
. Java (Java Design). -: Prentice-Hall, 1997.
C# .NET. Java-,
.
TestShop: C# .NET
using System;
namespace TestShop
{
class TestShop
{
public static void Main()
{
Shop shop = null;
Console.WriteLine(" PizzaShop:" + "\n");
shop = new PizzaShop();
string[] inventory = shop.getInventory();
//
for (int i= 0; i< 5; i++)
{
Console.WriteLine("" + i+ " = " + inventory[i]);
}
178 8.
//
shop.buyInventory(inventory[1]);
}
}
public abstract class Shop {
public void CalculateSaleTax() {
Console.WriteLine(" ");
}
public abstract string[] getInventory();
public abstract void buyInventory(string item);
}
public interface Nameable {
string getName();
void setName(string name);
}
public class PizzaShop : Shop , Nameable
{
string _CompanyName;
string[] foodOfferings = {
"",
"",
" ",
"",
""
}
public override string[] getInventory() {
return foodOfferings;
}
public override void buyInventory(string item) {
179
,
Console.WriteLine("\n " + item);
}
public string getName(){
}
return _CompanyName;
_CompanyName = name;
}
public class DonutShop : Shop , Nameable {
string _CompanyName;
string[] menuItems = {
"",
"",
" ",
"",
""
}
public override string[] getInventory() {
return menuItems;
}
public override void buyInventory(string item) {
Console.WriteLine(string.format("\n {0}.", item);
}
public string getName(){
}
return _CompanyName;
_CompanyName = name;
9.
-
.
7 ,
. 8 , , , , ,
.
, . , ,
. , .
. ,
, ,
.
.
,
,
. Person Employee (.9.1).
, . Employee Person.
Employee Person. Employee
Person, Employee Person.
. . , 8
, ,
.
: ,
. -
181
, .
, (.9.2).
.9.1.
.9.2.
, .
. ,
.
182 9.
. , ,
, .., , .
.
, , ,
. ,
, .
.
7 8 - Java (Object-Oriented Design in Java)
.
. .
,
, , ,
.
, . ,
, : .
, ,
. ? 1962
(The Architecture of Complexity) (Herbert
Simon) .
,
,
, , , ,
.
.
, , , .
, . , ,
, , .
183
, , .
,
, ,
.
, (.9.3) ( ). ,
CD- ?
. , ,
.
.9.3. ,
Java
, .NET. ,
184 9.
. ,
Java- (
),
. , .
, , .
CD-, (, ).
, ,
, . , .
CD-, .
CD- , .
. ,
, .
,
,
.
.
, , ,
, . -
,
, , .
. .
,
, .
?
- , ?. ,
,
. , . , .
.
,
, .
, , .
185
, .
, . ,
. , .
, ,
, .. , / , , . . ,
: , ,
... : .
, ,
. ,
. .
, , , ,
(.9.4).
.9.4. Car
186 9.
, , , .
,
(
).
(.9.5). , . ,
, .
, .
, ,
. ,
.
,
.
, . , , .
.9.5.
, , :
, , , , . ,
, .
, ,
, .
, , ,
. ,
, , ,
, ..
187
, Employee Address Spouse. , ,
, Address ( ,
Employee), Spouse . ,
Employee Spouse . , Spouse , .
, CD-. ,
CD- , ,
, .
, , .
, - ,
. .
, , .
.
. . , .
CD- , . ,
, CD-,
. CD- MP3- . , CD- MP3-
. , CD-
, .
.
: / /
DVD-.
- , . , , DVD-
.
DVD-, ,
.
, : . .
. /
,
(.9.6).
188 9.
.9.6.
, . /
, .
- Java
(Object-Oriented Design in Java)
, , ,
. ,
.
?
?
?
, . Employee, Person
:
Division;
JobDescription;
Spouse;
Child.
? ? Employee?
Division.
, , .
189
,
.
.
JobDescription.
, ,
, ,
.
, .
. ,
. , ,
, . ,
,
, .
Spouse.
Spouse .
. , Spouse
.
.
Child.
Child FavoriteToy.
.
(!).
, .
, .9.1
, .
9.1.
Employee/Division
Employee/JobDescription
1...n
Employee/Spouse
0...1
Employee/Child
0...n
0...1 , .
0...n,
.
190 9.
.9.7 .
,
. .9.1, , .
.9.7. UML-
, (, 0 ) ?
Employee:
import java.util.Date;
public class Employee extends Person{
private String CompanyID;
private String Title;
191
:
private Date StartDate;
private
private
private
private
Spouse spouse;
Child[] child;
Division division;
JobDescription[] jobDescriptions;
, , -, :
private Child[] child;
private JobDescription[] jobDescriptions;
,
,
. ,
, null .
, ,
.
, (.9.8).
, , , . , null,
.
, ,
Spouse, . ,
Employee, Spouse.
:
, , , , .
, 8,
: Owner ,
walkDog.
192 9.
.9.8.
. Dog Head ,
Head Dog. , ,
193
, , Dog
Head.
Dog Owner . Owner,
, Dog ,
. Dog Owner
walkDog. , ,
Dog Owner, , Dog , (, , , , ).
, , , , - .
HEAD?
, , , Head Mammal,
Dog, . Dog ,
Head Dog.
,
.
, .
.
,
. , UML-
, .
, ., ., .,
. - (Object-Oriented Analysis and Design with Applications).
3-. : Addison-Wesley, 2007.
. -
Java (Object-Oriented Design in Java). : The Waite Group Press
(Pearson Education), 1998.
10.
, , - . , ,
. , UML- , 1.
, 19.
, .
UML- ,
, .
UML,
, .
.
, ,
UML.
UML- - , , , .
.
UML, .
. -
, , . .
UML
UML, , .
UML. (The UML User Guide) UML
, , , . UML
. , UML
- .
, , .
195
UML ,
(Grady Booch), (James Rumbaugh) (Ivar Jacobson),
. Rational Software
, ,
, .
,
UML.
UML -
. UML
(What the UML Is and Isnt) :
, UML, , UML-, , - .
, , .
,
-
UML- .
UML ,
- . UML
- , .
: ,
(, ).
, .
. .10.1 UML-, Cabbie.
196 10.
UML- Java-:
/*
Cabbie Cab
*/
public class Cabbie {
// companyName
private static String companyName = "Blue Cab Company";
// name, Cabbie
private String name;
// Cab, Cabbie
// Cabbie
public Cabbie() {
name = null;
myCab = null;
}
// Cabbie
public Cabbie(String iName, String serialNumber) {
Name = iName;
myCab = new Cab(serialNumber);
}
// name, Cabbie
public void setName(String iName) {
name = iName;
}
// name, Cabbie
public String getName() {
return name;
}
// giveDirections Cabbie
public void giveDirections(){
}
// turnRight Cabbie
private void turnRight(){
}
// turnLeft Cabbie
private void turnLeft() {
197
}
// companyName
public static String getCompanyName() {
return companyName;
}
}
, UML- . , ,
. , , .
.
.
, .
, . Cabbie:
-companyName:String
-name:String
String. :
, ( String). , int float, :
-companyNumber:float
-companyAge:int
, , . ,
private (), . (+)
, public. , private.
, public, private .
, , , . , .
198 10.
Cabbie, , (, public, private):
+Cabbie:
+giveDirections:void
+getCompanyName:String
public ( ). private,
. , .
, :
+getCompanyName( ):String
:
+getCompanyName(1, 2, 3):String
, ,
, .
, .
(, ) .
, (+) (),
, ,
. ,
. , ; .
,
. , , :
-companyNumber:float
+companyAge:int
companyNumber ,
- . companyAge ,
.
, ,
, :
companyNumber:float
companyAge:int
199
Java protected. ,
. Java- ,
.
MSDN- Microsoft, .NET
:
public
, ;
private
;
protected
;
internal ,
. Objective-C ( @public ) ( @private ).
Objective-C ,
.
, , Dog
7. GoldenRetriever Dog, .10.2. UML ,
, .
,
.
,
.
200 10.
Java,
.
.NET Objective-C. C++
.
. - Dog 7 (.10.3).
. ,
. ,
. .10.3 .
,
Canine (.10.4).
, Eiffel
C++, , , .
,
. , . , .
,
. .10.5,
201
8. Dog Mammal
Nameable.
.10.5. UML-
.
(-
, ),
.
202 10.
9 .
.
(, ,
). (, ).
, . ,
Car 9 SteeringWheel
, , .10.6.
.10.6. UML-,
, (). , .10.7,
. ,
. , Stereo Car, Radio Stereo, Tuner
Radio.
, ,
, ,
.
, / . , , ,
, .
, . UML-
,
(.10.8).
203
.10.7. UML-,
.10.8. UML-,
, , -
, . , .
204 10.
, 9. : Computer, Monitor,
Scanner, Keyboard Mouse.
, Computer (.10.9).
.10.9. UML-,
, Monitor Computer.
, , . Computer , Motherboard, RAM .. (.10.10).
.10.10. UML-,
.
, .
205
, ,
.
,
, .
, , , . ,
1...n, n
, .
,
, , , . ,
n 6, 16.
, .9.7. . -, Employee
Spouse.
( ,
). , 0...1.
Employee Child ,
,
. , ,
. ,
0...n, n , .
Employee Division , .
.
.
. , . ,
.
Employee
JobDescription.
. Child,
,
. ,
1...n. ,
( ).
206 10.
, , . .
,
, , , .
UML- ,
. , UML
, ( ).
-
. UML
- ,
.
.
UML , , -
. , , :
? UML , .
- (, UML), (, Java). , C++ Java,
UML. ,
, ,
- .
, - . , -
. , , . - .
207
11.
: XML JSON
-
.
. , . .
, Java
, .
- Java ,
Java. .NET
. , C# .NET,
, Visual Basic .NET , ,
.NET- . ,
, (Java, .NET,
Objective-C.) - . ,
, , , .
, , , . ,
, , . .
.
XML (JSON ).
- , Java, VB C#, - , XML JSON, . XML JSON
,
.
209
, . ,
Oracle . , SQL Server
. ,
,
. ,
, ,
.
, SQL Server,
,
Oracle.
,
, .
, -,
, .
XML
. . , .
, , ( ,
, FpML ), , .
. . ,
XML .
XML-
.
. . .11.1 ,
.
XML
Recipe Markup Language (RecipeML). RecipeML XML, .. RecipeML
- . , XML, , , , , .
.
( ), ,
, (
). Java, .NET Objective-C
.11.1. XML
XML
XML . , ,
HTML. SGML . , SGML
1970-, 1980-.
HTML .
, . HTML , . HTML
SGML,
, SGML.
, SGML , . , HTML .
, XML .
1997 SGML. XML
, HTML, . XML . (W3C)
,
. -
W3schools (http://www.w3schools.com/).
, XML
- , -,
, ..
, XML (JSON).
211
XML HTML
Java ,
( Oracle). .NET
( Microsoft), Objective-C( Apple). XML , . ,
, . , XML .
XML HTML
XML ,
HTML. , SGML,
XML . HTML XML . HTML, CSS ( ),
, XML . ,
-.
XML HTML. ,
. XML , HTML, , .
HTML- . , <HTML>, <HEAD>, <BODY> ..,
HTML. .
HTML , .
XML . . (DTD).
,
. XML-
. XML- . XML- ,
. , .
. XML- .
XML- , .
, .
DTD.
, , <PurchaseOrder> .
, , , <PurchasOrder>,
.
XML -
XML - , .
, , ,
XML. , , . ,
, Oracle, , , SQL Server.
, . .
, , . , , , . , , ,
.
;
, , ,
, .
. ,
( - ). ,
,
.
XML. XML-,
.
, , XML-, ,
. -
213
. , Java, VB C#, , SQL Server
XML- .
XML-
, XML-
, XML-, Oracle.
.11.2 . , SQL /,
/.
Oracle.
.11.2.
, . , .
, . , , , print .
.
XML-,
.
, , .11.1.
,
.
11.1. ,
supplier
name
<companyname>
address
<street>
<city>
<state>
<zip>
product
<type>
<price>
<count>
(DTD)
XML- . XML- , , .
, . ,
, , supplier, , . , , . ,
, . 11.1.
11.1.
XML- ,
, .
, XML , .
, . .
XML-.
:
<!ELEMENT supplier ( name, address, product)>
supplier.
, supplier name, address product.
, XML- XML-,
supplier, name, address product.
, , name
<companyname>:
<!ELEMENT name ( companyname)>
215
(DTD)
<companyname> ,
#PCDATA:
<!ELEMENT companyname ( #PCDATA)>
.
supplier.dtd. . .11.3
, ,
.
.11.3.
XML-, ,
, , . DTD
, XML- , . ,
. , DTD.
<!-- supplier -->
<!ELEMENT supplier ( name, address)>
<!ELEMENT name ( companyname)>
<!ELEMENT companyname ( #PCDATA)>
<!ELEMENT address ( street+, city, state, zip)>
<!ELEMENT street ( #PCDATA)>
<!ELEMENT city ( #PCDATA)>
<!ELEMENT state ( #PCDATA)>
<!ELEMENT zip ( #PCDATA)>
<!ELEMENT product ( type, price, count)>
<!ELEMENT type ( #PCDATA)>
<!ELEMENT price ( #PCDATA)>
<!ELEMENT count ( #PCDATA)>
XML-
, ,
XML-. , , .
.11.2 , XML-. - ,
, address name.
11.2.
supplier
name
<companyname>
address
<street>
-, 12000
<city>
<state>
<zip>
24388
<type>
<price>
50.00
<count>
20
product
XML-,
, .
, , . .11.4 XML-,
. beta.xml.
.11.4. XML-
217
XML-
, suppli
er.dtd, :
<!DOCTYPE supplier SYSTEM "supplier.dtd">
.11.4, , .
,
- . , , .
- .
<address> ,
. <street> ,
. , <street> , <address>:
<address>
<street>-, 12000</street>
XML-.
, XML- .
XML Notepad , ,
Microsoft.
XML NOTEPAD
, - XML Notepad. .
supplier.dtd.
.11.7. ,
, , . XML-,
.
219
XML-
.11.7. ( )
, supplier.dtd.
, ? gam
ma.xml XML-, , W3schools
(www.w3schools.com/xml/xml_validator.asp). , .11.8. XML- , , .
,
supplier.dtd, . , .
,
. , XML-
, ,
. ,
<address>.
, HTML. , ,
XML- ,
.11.9.
.11.9. gamma.xml ( ),
Internet Explorer
, , , . , ,
, XML . ,
XML ( ). HTML , XML
221
CSS
, ,
. .
: XML
Notepad supplier ?
: XML Notepad -
, , .
: XML Notepad .
CSS
.
,
.
, , XML-,
.
, XML ,
HTML, . XML HTML
.
XML ,
XML-.
CSS . CSS
HTML . CSS
XML-. , XML supplier <companyname> , <street> , <city> ,
<state> <zip>. , , .11.3, ,
XML-
.
11.3. CSS-
(font-family)
(font-size)
(color)
(display)
24
blue
block
<street>
12
red
block
<city>
18
black
block
<state>
Tahoma; serif
16
gray
block
<zip>
green
block
CSS
:
,
XML-:
<?xml-stylesheet href="supplier.css" type="text/css" ?>
223
JavaScript Object Notation (JSON)
, JSON- , . , JSON-
/. , JSON , ,
W3schools. ,
, (http://www.w3schools.com/json/json_
intro.asp):
<!DOCTYPE html>
<html>
<body>
<h2> JSON- JavaScript</h2>
<p>
: <span id="jname"></span><br />
: <span id="jage"></span><br />
: <span id="jstreet"></span><br />
: <span id="jphone"></span><br />
</p>
<script type="text/javascript">
var JSONObject= {
"name":" ",
"street":"-, 555",
"age":33,
"phone":"5551234567"};
document.getElementById("jname").innerHTML=JSONObject.name
document.getElementById("jage").innerHTML=JSONObject.age
document.getElementById("jstreet").innerHTML=JSONObject.street
document.getElementById("jphone").innerHTML=JSONObject.phone
</script>
</body>
</html>
225
JavaScript Object Notation (JSON)
JSON- W3SHOOLS
, , W3shools,
. , ( ..), . , ,
- . ,
.
, XML-, , JSON:
var address= {
"street":"-, 23456",
"city":"",
"state":"",
"zip":"24388"
};
JSON- JavaScript-
/, . .11.11
, JSON- HTML.
, JSON- ,
XML- ,
:
<!DOCTYPE html>
<html>
227
JavaScript Object Notation (JSON)
W3schools , .11.12.
, , XML-
Internet Explorer .11.10, JSON-.
; JSON- ( HTML) Internet Explorer. .11.13.
, XML JSON -
, .
, , , , .
XML, ,
, .
,
, XML. JSON.
XML, JSON ,
.
- ,
, -
-, .
, - , .
-
.
, ,
XML JSON. ,
, XML JSON,
, . ,
. CSS ,
XML-.
http://www.w3schools.com/json/default.asp.
12.
:
,
, - ,
, , . ,
:
. , , ,
, ..
, ,
, .
,
, , ,
, . ,
Employee, ,
name, ss# .., ,
. .12.1 , . ,
. ,
. ,
- .
Employee . ,
. Employee,
.
.
, ,
. .12.2 . 1,
, .
,
230 12.
. , 2
.
.12.1.
.12.2.
. :
;
;
.
231
,
,
. ,
,
-, , .
. ,
. , .
, .
, , . ,
- ,
.
, , , , ,
.
, .
(,
..), .
, ,
, , , .
, . , . , , ,
, .
, , , , , .
,
. , Car
, Engines Wheels. , Car,
Engines .., .
. , Java,
C, , /. Java ,
232 12.
Stream. Stream
Serializable, Externalizable.
, Java, . Java . ,
XML-
XML-.
.
Java Java,
XML- .NET- C#.
Java- Person:
package Serialization;
import java.util.*;
import java.io.*;
class Person implements Serializable{
private String name;
public Person(){
}
public Person(String n){
System.out.println(" Person");
name = n;
}
String getName() {
return name;
}
}
, ,
.
, , Seriali
zable. Java, , Serializable
, :
class Person implements Serializable
getName, .
, Serializable,
, . .
233
,
. SavePerson :
package Serialization;
import java.util.*;
import java.io.*;
public class SavePerson implements Serializable{
public SavePerson(){
Person person = new Person(" ");
try{
FileOutputStream fos = new FileOutputStream("Name.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
System.out.print(" : ");
System.out.println(person.getName());
oos.writeObject(person);
oos.flush();
oos.close();
} catch(Exception e){
e.printStackTrace();
}
}
}
Java, , ,
() .
JAVA-
, ,
-, , , .
, . ? ,
. .
1. Person.
2. .
3. Name.txt.
:
oos.writeObject(person);
, . .
234 12.
,
, . ,
.
, , .
.
. .
:
;
, .
, . ,
,
.
, , , .
SavePerson Name.txt.
:
package Serialization;
import java.io.*;
import java.util.*;
public class RestorePerson{
public RestorePerson(){
try{
FileInputStream fis = new FileInputStream("Name.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
Person person = (Person )ois.readObject();
System.out.print(" : ");
System.out.println(person.getName());
ois.close();
} catch(Exception e){
e.printStackTrace();
}
}
}
,
Name.txt:
Person person = (Person )ois.readObject();
, ,
Person . Person
235
Person, SavePerson . .12.3 SavePerson ,
RestorePerson.
.12.3.
?
, ,
: , , ?
, , , , .
?
Java . ,
, , Java .
.
, Person SavePerson
RestorePerson Person.
Person, ,
, . .
, , . - ,
.
236 12.
XML
,
. XML ,
XML- , ,
,
. XML-, , , C# .NET. ,
XML- ,
Java .
XML- Java ,
XML-.
Person. Person;
.
C#-. Person .
, XML (, , ..),
XML.
, XmlRoot, XmlAttribute XmlElement
. :
[XmlRoot("person")]
public class Person
...
[XmlAttribute("name")]
public String Name
...
[XmlElement("age")]
public int Age
,
. , , ,
. , , ,
. , ,
(, , ) . ,
,
. XML-
, .
, XML- Name :
237
XML
[XmlAttribute("name")]
public String Name
{
get
{
return this.strName;
}
set
{
if (value == null) return;
this.strName = value;
}
}
, , ,
:
public String Name;
, String,
Name XML-, Name .
- ;
( ,
).
Name , :
this.Name = name;
set .
( , CC++). ( )
Name ( ), .
inline.
XML- Person Java. :
public void Serialize()
{
Person[] myPeople = new Person[3];
myPeople[0] = new Person(" ", 32, 95);
myPeople[1] = new Person(" . ", 35, 67);
myPeople[2] = new Person(" . ", 65, 77);
XmlSerializer mySerializer = new XmlSerializer(typeof(Person[]));
TextWriter myWriter = new StreamWriter("person.xml");
mySerializer.Serialize(myWriter, myPeople);
myWriter.Close();
}
,
Java- XML:
238 12.
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Person name=" ">
<age>32</age>
</Person>
<Person name=" . ">
<age>35</age>
</Person>
<Person name=" . ">
<age>65</age>
</Person>
</ArrayOfPerson>
:
public void DeSerialize()
{
Person[] myRestoredPeople;
XmlSerializer mySerializer = newXmlSerializer(typeof(Person[]));
TextReader myReader = new StreamReader("person.xml");
myRestoredPeople = (Person[])mySerializer.Deserialize(myReader);
Console.WriteLine(" :");
foreach (Person listPerson in myRestoredPeople)
{
Console.WriteLine(listPerson.Name + " " + listPerson.Age
+ " .");
}
Console.WriteLine(" , ...")
Console.ReadKey();
}
, foreach. C#
.
,
, XML-
, XML-, Java. Java- ,
. XML-
Java.
, , , - . , , ,
. ,
.
239
, . Oracle
SQL Server Microsoft Access,
.
,
, .
,
, , , -
.
. .12.4 Microsoft Access.
, . -
. .12.4
Northwind, Microsoft Access.
.12.4.
, 1990-
- .
- , : .
, . , .
, ,
.
.
240 12.
, - .
, . .
, ,
, . ,
,
,
. .
-, ,
,
, , . -,
, ,
. -,
( ), ,
. . ,
, . ,
- .
: ,
. .
. :
;
;
.
,
. ,
, .
SQL
SQL .
, .
SQL. .12.5 /
.
Java
Microsoft Access. Java JDBC ( Java) .
241
.12.5. /
,
. . ,
, ,
, , . .
.
, ,
.
, .
Microsoft Open Database
Connectivity (ODBC) .
Java2 (Java 2
Platform Unleashed), ODBC-
,
.
API- ODBC, ,
. .12.6.
, ODBC .
.12.6. / ODBC
API-. ODBC, ,
, . , ODBC, , Microsoft
Access Oracle.
.12.5, SQL-
. Java JDBC .
242 12.
, JDBC -. , JDBC . ODBC , .12.7.
.12.7. / ODBC/JDBC
, , .
, , . , ,
Java2 (Java2 Platform Unleashed).
. - ,
, .
,
.
, , , , , ,
.
.
.
243
,
. -
Web Warrior (The Web Warrior Guide to Web Database Tech
nologies). : Course Technology (Cengage), 2004.
. C# . (C# for Experienced
Programmers). --: Prentice Hall, 2003.
. Visual Basic .NET (Visual Basic .NET
for Experienced Programmers). --: Prentice Hall, 2003.
. Java 2 (Java 2 Platform Unleashed).
: Sams Publishing, 1999.
. Java Enterprise. (Java Enterprise in aNutshell).
: OReilly, 1999.
. Java (Java Distributed Computing).
: OReilly, 1998.
Oracle: http://www.oracle.com/technetwork/java/index.html
C# .NET. Java, .
Person: C# .NET
// Person
using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace CSSerial
{
[XmlRoot("person")]
public class Person
{
private String strName;
private int intAge;
private int intScore;
public Person()
{
this.Name = " ";
this.Age=25;
this.Score=50;
}
public Person(String name, int age, int score)
244 12.
{
this.Name = name;
this.Age = age;
this.Score = score;
}
[XmlAttribute("name")]
public String Name
{
get
{
return this.strName;
}
set
{
if (value == null) return;
this.strName = value;
}
}
[XmlElement("age")]
public int Age
{
get
{
return this.intAge;
}
set
{
this.intAge = value;
}
}
[XmlIgnore()]
public int Score
{
get
{
return intScore;
}
set
{
this.intScore = value;
}
}
}
}
// CSSerial
using System;
245
,
using
using
using
using
System.Collections;
System.IO;
System.Xml;
System.Xml.Serialization;
namespace CSSerial
{
class Program
{
static void Main(string[] args)
{
Program myProgram = new Program();
}
public Program()
{
Serialize();
DeSerialize();
}
public void Serialize()
{
Person[] myPeople = new Person[3];
myPeople[0] = new Person(" ", 32, 95);
myPeople[1] = new Person(" . ", 35, 67);
myPeople[2] = new Person(" . ", 65, 77);
XmlSerializer mySerializer = new XmlSerializer(typeof(Person[]));
TextWriter myWriter = new StreamWriter("person.xml");
mySerializer.Serialize(myWriter, myPeople);
myWriter.Close();
}
public void DeSerialize()
{
Person[] myRestoredPeople;
XmlSerializer mySerializer = new XmlSerializer(typeof(Person[]));
TextReader myReader = new StreamReader("person.xml");
myRestoredPeople = (Person[])mySerializer.Deserialize(myReader);
Console.WriteLine(" :");
foreach (Person listPerson in myRestoredPeople)
{
Console.WriteLine(listPerson.Name + " " + listPerson.Age
+ " .");
}
Console.WriteLine(" , ...");
Console.ReadKey();
}
}
}
13.
-,
, , ,
, .
- , ,
.
, ,
, ,
.
( 1990-), -
Smalltalk 1980-1990-,
C++ 1990-. C++
. Java, , -
. , .NET Objective-C, -
. , .
, .
, . , ,
. ,
. COBOL,
,
.
,
247
, - . .
.
,
. , ,
:
HTML;
EDI;
;
CORBA;
DCOM;
XML;
SOAP;
-;
ReST.
-
. , Java, .NET Objective-C, , .
- ,
. , C++
- ,
,
- .
- C,
C++. , , JavaScript, VBScript, ASP, JSP, PHP, Perl
Python.
- . , . -
, , .
, ,
,
, , -.
/. .13.1 .
248 13. -,
.13.1. /
, / .
, , ,
, -. .
, -,
:
.
, (.13.2).
.13.2. HTML-
249
HTML-;
. ,
/, :
,
.
, , , . , , , - -5.
, . , .
. - , .
.
, () . ,
, . .
/,
.
. ,
.
, , HTML- .13.2,
. -, (
), .
, , , .
, ?
, , ,
. , , , .
,
, . ,
, , .
. ,
: , ?
250 13. -,
, , , ,
.
. :
;
;
;
.
, - , .
.
JavaScript
JavaScript, ,
. C++, JavaScript-,
- . JavaScript
- . , JavaScript ASP.NET, - . JavaScript-
-. - - . , , -
.
,
HTML. HTML ,
. ,
HTML if . ,
HTML
. .
, JavaScript
, - , . HTML JavaScript. -
:
<html>
<head>
251
JavaScript
<title> </title>
<script type = "text/javascript">
function validateNumber(tForm) {
if (tForm.result.value != 5 ) {
this.alert (" 5!");
} else {
this.alert (". !");
}
}
</script>
</head>
<body>
<hr>
<p>
<h1></h1>
<form name="form">
<input type="text" name="result" value="0" SIZE="2">
<input type="button" value="" name="calcButton"
onClick="validateNumber(this.form)">
</form>
<hr>
</body>
</html>
, JavaScript-
HTML-. ,
. Java C# , ,
JavaScript . JavaScript-
(,
jQuery).
JAVA JAVASCRIPT
Java JavaScript C, .
-
(.13.3).
, . , 5. 5,
,
(.13.4).
5, ,
, .
JavaScript, :
HTML-.
252 13. -,
.13.3. JavaScript
.13.4. JavaScript
,
JavaScript.
validateNumber():
<script type = "text/javascript">
function validateNumber(tForm) {
if (tForm.result.value != 5 ) {
253
-
this.alert (" 5!");
} else {
this.alert (". !");
}
}
</script>
JAVASCRIPT-
,
, JavaScript,
.
.
HTML-:
<input type="button" value="Validate" name="calcButton"
onClick="validateNumber(this.form)">
, , validateNumber().
-
HTML- . ,
JavaScript . HTML-.
.
.
,
PowerPoint Flash.
, -.
JavaScript-
, Java
Script-, . ,
validateNumber(). , , , .., , .
- , :
textbox;
button;
form.
. ,
color button label.
254 13. -,
, form , .
, - ( ). , value
textbox ( result) form ( tForm):
if (tForm.result.value != 5 )
, alertbox .
this :
this.alert (". !");
THIS
, this , form.
JavaScript . .13.5
.
.13.5. JavaScript-
, JavaScript . , , Date .
255
-
, getHours()
getMinutes(). . Date:
<html>
<head>
<title> Date</title>
</head>
<body>
<script language="JavaScript" type = "text/javascript">
days = new Array ( "", "", "",
"", "", "",
"", "");
today=new Date
document.write(" " + days[today.getDay()]);
</script>
</body>
</head>
</html>
, Array,
, .
today, , .
-
.
-
HTML- .
- .
<object>. Slider, -. HTML- , :
<html>
<head>
<title></title>
</head>
<body>
<object classid="clsid:F08DF954-8592-11D1-B16A-00C0F0283628" id="Slider1"
width="100" height="50">
<param name="BorderStyle" value="1" />
<param name="MousePointer" value="0" />
<param name="Enabled" value="1" />
<param name="Min" value="0" />
256 13. -,
<param name="Max" value="10" />
</object>
</body>
</html>
, , .13.6.
, . , height width, , . , <object>.
.13.6. -
, ,
. Internet Explorer8 Windows7.
<object>
.
, , ,
.
, HTML-
, <object>. , :
<html>
<head>
257
-
<title></title>
</head>
<body>
<object
classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
<param name="FileName" value="fanfare.wav" />
</object>
</body>
</html>
, .
( .wmv) <object>.
,
-:
<html>
<head>
<title></title>
</head>
<body>
<object
classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
<param name="FileName" value="AspectRatio4x3.wmv" />
</object>
</body>
</html>
Flash
, Flash- <object>:
<html>
<head>
<title></title>
</head>
<body>
<object width="400" height="40"
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com
/pub/shockwave/cabs/flash/swflash.cab#4,0,0,0">
<param name="SRC" value="intro.swf">
<embed src="bookmark.swf" width="400" height="40"></embed>
258 13. -,
</object>
</body>
</html>
, .
, .
?
,
. ,
, , ,
.
.
,
. ,
, , ,
. , -
, . ,
, URL-.
.
? ,
. , ,
. ,
- .
, .
, . , ,
,
, ,
. . . .13.7 , .
-
, , ,
. ,
, .
: ()
(), -
, , . -
259
( ),
.
.13.7.
, , - .
, CORBA ,
, 1990-. ,
, , -,
- CORBA-. SOAP, XML
- .
, .
260 13. -,
, .
, ,
.
. ; ,
, , . ,
.
,
.
.
. ,
, , . . , , Java, , C++.
,
. CORBA (
) ,
1990-.
CORBA : , CORBA
.
. ,
, , .
CORBA , DCOM, .
CORBA ( Java- RMI), , ,
. , ,
. .
, .13.8 .
, ( - ).
. . (, ,
) . .
261
.13.8.
. ,
-
(Object Management Group OMG), : CORBA-
. , ,
. ,
,
( )
- .
,
-.
, .
, , , -.
, ,
-.
, , name, address
.., . , -, . , ..
,
. , . , .
, .
CORBA
, , , ,
262 13. -,
. CORBA , . CORBA- ,
8. CORBA-
(IDL). , ,
, ,
, IDL.
, , . ,
, : , ,
, ,
. , ,
IDL,
.
, CORBA-,
, (Object Request
Broker ORB). , , , ORB CORBA.
CORBA-.
, .
- , CORBA , .
, -
, :
, IDL,
CORBA.
:
, , IDL-, ( ),
.
, IDL,
, 8. UML-,
.8.7, Shop.
Inventory, - :
interface Inventory {
string[] getInventory ();
string[] buyInventory (in string product);
}
, ,
. :
263
, ;
, .
IDL- ,
. .13.9 , CORBA.
.13.9. CORBA
, ,
, , . (
). ,
, .
. ,
,
. , ,
, . .13.10 ,
, .
TCP/IP
HTTP , , TCP/IP
(Internet Inter-ORB Protocol IIOP) , .
IIOP , CORBA Java RMI.
-
,
CORBA, DCOM RMI. , , - , , SOAP, XML, .
264 13. -,
.13.10. ,
-
- .
, ,
.
-,
, : ,
XML- SOAP
(Simple Object Access Protocol ).
SOAP . SOAP ,
XML. SOAP
HTTP,
. SOAP HTTP
-.
(Remote Procedure Call RPC)
. SOAP
HTTP XML. ,
SOAP : SOAP XML
.
, () .
-,
(Remote Method Invocation RMI). ,
( ), . , , .
.
CORBA DCOM ,
.
SOAP , XML
265
CORBA DCOM.
, XML
12.
, CORBADCOM- . ,
, . , ,
, SOAP, , - .
,
. SOAP ,
DCOM, Enterprise
JavaBeans CORBA,
. ,
.
SOAP, , ,
HTML, ,
. - SOAP
DCOM, Enterprise JavaBeans,
CORBA RMI, , .
SOAP-
, SOAP-,
- .
SOAP
, ,
.
Warehouse.
, , ,
- Warehouse, - .
.13.11 .
.13.11. SOAP-
266 13. -,
mwsoap.xml XML- ,
-. Invoice.xsd :
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://ootp.org/invoice.xsd"
elementFormDefault="qualified" xmlns="http://ootp.org/invoice.xsd"
xmlns:mstns="http://ootp.org/invoice.xsd" xmlns:xs="http://www.w3.org/2001/
XMLSchema">
<xs:element name="Invoice">
<xs:complexType>
<xs:sequence>
<xs:element name="Address" minOccurs="1">
<xs:complexType>
<xs:sequence />
<xs:attribute name="Street" type="xs:string" />
<xs:attribute name="City" type="xs:string" />
<xs:attribute name="State" type="xs:string" />
<xs:attribute name="Zip" type="xs:int" />
<xs:attribute name="Country" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="Package">
<xs:complexType>
<xs:sequence />
<xs:attribute name="Description" type="xs:string" />
<xs:attribute name="Weight" type="xs:short" />
<xs:attribute name="Priority" type="xs:boolean" />
<xs:attribute name="Insured" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
Invoice.xsd , Invoice
.
, . , Invoice.xsd Invoice Address Package.
, Address Package , Description, Weight
.. , ,
string, short .. .13.12 ,
.
Invoice.xsd , ,
mwsoap.xml , . , , , , C# .NET, VB .NET, ASP.NET Java, Invoi
ce.xsd XML-,
267
.
Invoice.xsd, mwsoap.xml .
Invoice.xsd - , , 8.
.13.12. Invoice.xsd ( )
mwsoap.xml SOAP/XML:
<?xml version="1.0" encoding="utf-8"?>
<soap:envelope xmlns:soap="http://www.w3.org/2001/06/soap-envelope">
<soap:Header>
<mySOAPHeader:transaction xmlns:mySOAPHeader="soap-transaction"
soap:mustUnderstand="true">
<headerId>8675309</headerId>
</mySOAPHeader:transaction>
</soap:Header>
<soap:Body>
<mySOAPBody xmlns="http://ootp.org/Invoice.xsd">
<invoice name=" ">
<address street="-, 475"
city=""
state=""
zip="23654"
country=""/>
<package description="22- "
weight="22"
priority="false"
insured="true" />
268 13. -,
</invoice>
</mySOAPBody>
</soap:Body>
</soap:envelope>
-
. C# .NET , Invoice, Address Package.
, .
SOAP/XML-.
XML-,
(.13.13). , .
.13.13. SOAP/XML-
, , ,
, .
, .
.
C# .NET , ,
.13.12.
Invoice.cs. C# .NET-
Invoice, .13.12:
using System;
using System.Data;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
namespace WebServices
{
[XmlRoot("invoice")]
public class Invoice
{
public Invoice(String name, Address address, ShippingPackage package)
269
{
this.Name = name;
this.Address = address;
this.Package = package;
}
private String strName;
[XmlAttribute("name")]
public String Name
{
get { return strName; }
set { strName = value; }
}
private Address objAddress;
[XmlElement("address")]
public Address Address
{
get { return objAddress; }
set { objAddress = value; }
}
private ShippingPackage objPackage;
[XmlElement("package")]
public ShippingPackage Package
{
get { return objPackage; }
set { objPackage = value; }
}
}
}
270 13. -,
, ReST, ReST.
ReST ,
HTTP- , , . ReST
-, , , SOAP,
. , ReST
-.
, XML ( ReST ). .13.14 , HTTP-/
ReSTful-.
.13.14. - ReSTful
SOAP , , , ReSTful-
XML-. SOAP, ReST, XML.
, ReST- - .
ReST , -
, ,
.
,
-. , - (, JavaScript-), , , ,
.
. ;
SOAP XML
.
271
14.
-
13 . , . /.
13 ( ). ,
/
. ,
- .
-
,
.
, / , .
/
, XML , . ,
,
SOAP/XML.
/.
XML. .
Java , Java, .
XML C# .NET.
Java , . ,
.
273
, .
.14.1.
.14.1. /
, . .
.
TextMessage name message.
.
TextMessage :
import java.io.*;
import java.util.*;
public class TextMessage implements Serializable {
public String name;
public String message;
// TextMessage
TextMessage(String n) {
message = " ";
name= n;
}
// -
public String getName() {
return name;
}
// -
public String getTextMessage() {
return message;
}
// -
274 14. -
public void setTextMessage(String inTextMessage) {
message = inTextMessage;
}
}
. name
message .
Java.
TextMessage , .
.
1. .
2. .
3. .
4. .
5. .
6. .
7. .
.
.
import java.io.*;
import java.net.*;
/*
* TextMessage
*/
public class Client {
public static void main(String[] arg) {
try {
String message = " ";
String name = " ";
System.out.print(", : ");
name = getString();
// TextMessage
TextMessage myTextMessage = new TextMessage(name);
System.out.print(": ");
message = getString();
275
// TextMessage
myTextMessage.setTextMessage(message);
//
Socket socketToServer = new Socket("127.0.0.1", 11111);
// ObjectOutputStream
ObjectOutputStream myOutputStream = new
ObjectOutputStream(socketToServer.getOutputStream());
// myTextMessage object OutputStream
myOutputStream.writeObject(myTextMessage);
//
myOutputStream.close();
} catch (Exception e) {System.out.println(e);}
}
public static String getString() throws Exception {
// ( 'stdin')
BufferedReader stdin =
new BufferedReader(new InputStreamReader(System.in), 1);
String s1 = stdin.readLine();
return (s1);
}
}
, ,
. ,
:
Socket socketToServer = new Socket("127.0.0.1", 11111);
, IP-
, .
IP- 127.0.0.1 , ,
. , . , .
IP- . ,
, .
IP-.
276 14. -
IP-, .
11111.
: , , .
,
, .
, ,
, .
, .
.
1. .
2. 11111.
3. .
4. / .
5. TextMessage.
6. .
:
import java.io.*;
import java.net.*;
/*
* TextMessage
*/
public class Server {
public static void main(String[] arg) {
// ,
TextMessage myTextMessage = null;
try {
// 11111
ServerSocket myServerSocket = new ServerSocket(11111);
System.out.println("\n");
// ,
Socket incoming = myServerSocket.accept();
// ObjectInputStream
ObjectInputStream myInputStream = new
277
ObjectInputStream(incoming.getInputStream());
//
myTextMessage = (TextMessage)myInputStream.readObject();
System.out.println(myTextMessage.getName() + " : "
+ myTextMessage.getTextMessage()+ "\n");
//
myInputStream.close();
} catch(Exception e) {
System.out.println(e);
}
}
}
, . , ,
.
, . ,
,
, .
/
/
,
.
,
.
. ,
, . , ,
. ,
.
,
, . .14.2 , .14.3
. - , ,
. , .
,
, . , ,
, (
), , ,
.
278 14. -
.14.2.
.14.3.
, ,
Java- . , Java-, .
. , , server.bat, server :
"C:\Program Files (x86)\Java\jdk1.6.0_35\bin\java" Server
, :
"C:\Program Files (x86)\Java\jdk1.6.0_35\bin\javac" Client.java
"C:\Program Files (x86)\Java\jdk1.6.0_35\bin\javac" Server.java
.
, XML, ,
.
XML- , ,
. , ,
.14.4.
279
.14.4. XML- /
,
,
XML- .
Chec
kingAccount.
XML- CheckingAccount , , , XML-
( 11). C# .NET
CheckingAccount:
using
using
using
using
using
System;
System.Collections;
System.IO;
System.Xml;
System.Xml.Serialization;
namespace Server
{
[XmlRoot("account")]
public class CheckingAccount
{
private String _Name;
private int _AccountNumber;
[XmlElement("name")]
public String Name
{
get { return _Name; }
set { _Name = value; }
}
[XmlElement("account_num")]
public int AccountNumber
{
280 14. -
get { return _AccountNumber; }
set { _AccountNumber = value; }
}
public CheckingAccount()
{
_Name = " ";
_AccountNumber = 54321;
Console.WriteLine(" !");
}
}
}
, , ,
, XML- .
, .NET- (C# VB) XML. Java. ,
XML-, ,
.
.
, C# .NET- .
.
1. CheckingAccount.
2. .
3. XML-.
4. .
5. .
6. .
7. .
. C# .NET:
using
using
using
using
using
using
using
using
System;
System.Collections;
System.IO;
System.Xml;
System.Xml.Serialization;
System.Net.Sockets;
System.Net;
System.Text;
namespace Client
{
281
class Client
{
public static void Connect()
{
CheckingAccount myAccount = new CheckingAccount();
try
{
// TCP-
TcpClient client = new TcpClient("127.0.0.1", 11111);
// CheckingAccount
// XML-
XmlSerializer myXmlFactory =
new XmlSerializer(typeof(CheckingAccount));
// TCP-
NetworkStream stream = client.GetStream();
// TCP-
myXmlFactory.Serialize(stream, myAccount);
//
stream.Close();
client.Close();
}
catch (Exception ex)
{
Console.WriteLine(": {0}", ex);
}
Console.WriteLine(" , ...");
Console.ReadKey();
}
}
}
(
) . ,
.
1. CheckingAccount.
2. .
3. .
4. .
5. .
6. .
7. .
282 14. -
C# .NET :
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Net.Sockets;
System.Net;
System.Xml;
System.Xml.Serialization;
System.IO;
System.Runtime.Serialization;
namespace Server
{
class Server
{
public Server()
{
TcpListener server = null;
TcpClient client = null;
try
{
//
server = new TcpListener(IPAddress.Parse("127.0.0.1"),
11111);
server.Start();
//
Byte[] bytes = new Byte[256];
//
while (true)
{
//
client = server.AcceptTcpClient();
Console.WriteLine(" !");
//
NetworkStream stream = client.GetStream();
//
int i;
while ((i= stream.Read(bytes, 0, bytes.Length)) != 0)
{
// ,
MemoryStream ms = new MemoryStream(bytes);
//
XmlSerializer myXmlFactory =
new XmlSerializer(typeof(CheckingAccount));
// CheckingAccount
283
myRestoredAccount =
(CheckingAccount)myXmlFactory.Deserialize(ms);
// ,
Console.WriteLine(": {0}, : {1}.",
myRestoredAccount.Name,
myRestoredAccount.AccountNumber);
//
throw new Exception("");
}
}
}
catch (Exception ex)
{
if (!ex.Message.Equals(""))
{ Console.WriteLine(": {0}", ex); }
}
finally
{
//
client.Close();
server.Stop();
}
Console.WriteLine(" , ...");
Console.ReadKey();
}
}
}
/
Visual Studio
C#. NET, , :
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Threading;
namespace Server
{
class Program
{
static void Main(string[] args)
{
Server server = new Server();
}
}
}
284 14. -
/. . Java
,
.
.NET ( C#, VB). XML
Java.
, 11 13, , , XML, , .
Java C# .NET.
15.
,
. ,
, ,
, .
-, -. - .
,
. ,
, ,
, , .
, Mammal,
, Dog, Cat ..,
. , Dog, Cat, Squirrel
, . , , , , , ,
, .
, .
, .
( , , 1995).
, , - .
,
. -
,
.
. ,
,
, - .
286 15.
, - , -
. (Design Patterns: Elements of Reusable
Object-Oriented Software), (Erich
Gamma), (Richard Helm), (Ralph Johnson)
(John Vlissides). , , , (GoF Gang of Four).
, (
). (, ), ,
.
, , .
. (Christopher
Alexander) : , , (APattern
Language: Towns, Buildings, Construction), ,
, , , .
.
, -
, . . .
, ,
.
.
.
, . -
. , .
, . ,
, .
, , ,
. ,
, ,
287
// Smalltalk
. , , ( ) .
.
,
, , .
,
.
. -
,
, .
.
//
Smalltalk
//
(Model/View/Controller MVC), Smalltalk ( - ). // .
Smalltalk. , Smalltalk .
SMALLTALK
Smalltalk Xerox PARC.
, . C++ , ,
Smalltalk, - . C++
- ,
Smalltalk .
: , , (APattern Language:
Towns, Buildings, Construction) //
:
, , , .
, ,
, . ,
. // , .
, ,
. .15.1 ,
//.
288 15.
.15.1. //
, -
.
.
. , ,
( ). // ,
.
,
- , .
// , - ,
. , , - , .
,
- . ,
- -,
. ,
-,
,
, -. , , ,
.
//
, ,
, .
, , , .
//
//
, , -
289
. ,
- , ,
. :
, ?
: , , (APattern Language: Towns,
Buildings, Construction) 23, ,
. C++,
Smalltalk. ,
C++ Smalltalk. 1995- , Java
. , ,
.
Java.
, , . : , , (APattern Language: Towns,
Buildings, Construction), , ,
. .
,
. , .
.
, .
,
, .
,
, .
:
Abstract factory ( );
Builder ();
Factory method ( );
Prototype ();
Singleton ().
290 15.
, ,
, . . ,
Singleton ().
Singleton (). (.15.2) ,
. , ,
Counter , ,
, , -
Counter. ,
,
.
.15.2. Singleton ()
, ,
.
, , ,
Factory (), Abstract Factory ( ) Bridge ().
, - ,
. , ,
, ,
static ..
291
, Singleton,
Instance(). , -
- . ,
Instance(), .
Java- Singleton:
public class ClassicSingleton {
private static ClassicSingleton instance = null;
protected ClassicSingleton() {
// ,
}
public static ClassicSingleton getInstance() {
if(instance == null) {
instance = new ClassicSingleton();
}
return instance;
}
Counter , :
public class Counter
{
private int counter;
private static Counter instance = null;
protected Counter()
{
}
public static Counter getInstance() {
if(instance == null) {
instance = new Counter ();
System.out.println(" \n");
}
return instance;
}
public void incrementCounter()
{
counter++;
}
public int getCounter()
{
return(counter);
}
}
292 15.
, , .
Counter. :
public static Counter getInstance() {
if(instance == null) {
instance = new Counter ();
System.out.println(" \n");
}
return instance;
}
, , instance null, , .
Counter. instance null, ,
Counter, .
.
Singleton. , Singleton, .
, , , , Singleton .
:
public class Singleton
{
public static void main(String[] args)
{
Counter counter1 = Counter.getInstance();
System.out.println(" : " + counter1.getCounter() );
Counter counter2 = Counter.getInstance();
System.out.println(" : " + counter2.getCounter() );
}
}
COUNTER
, Counter . ,
Counter ,
.
Singleton Counter. , :
Counter counter1 = Counter.getInstance();
. getInstance(). .15.4 ,
. ,
293
. counter2 , counter1.
, counter1 counter2 . :
public class Singleton
{
public static void main(String[] args)
{
Counter counter1 = Counter.getInstance();
counter1.incrementCounter();
counter1.incrementCounter();
System.out.println(" : " + counter1.getCounter() );
Counter counter2 = Counter.getInstance();
counter2.incrementCounter();
System.out.println(" : " + counter2.getCounter() );
}
}
.15.5 Singleton. ,
counter1 ,
2. counter2
, counter1,
3 (2+1).
294 15.
, ,
, Java- . Singleton,
Singleton.bat, Singleton :
"C:\Program Files (x86)\Java\jdk1.6.0_35\bin\java" Singleton
.
:
Adapter ();
Bridge ();
Composite ();
Decorator ();
Facade ();
Flyweight ();
Proxy ().
Adapter
(). . , .
Adapter (). ,
.
. , , (
)
. Java- Integer,
. , . , - .
Java , , .., .
- , , . . ,
:
int myInt = 10;
Integer:
Integer myIntWrapper = new Integer (myInt);
,
:
String myString = myIntWrapper.toString();
295
, .
, Adapter () , MailTool. , , , .
, ,
, . ,
, API- .
:
package MailTool;
public class MailTool {
public MailTool () {
}
public int retrieveMail() {
System.out.println (" ");
return 0;
}
}
retrieveMail()
. ,
retrieveMail()
getMail(). , :
package MailTool;
interface MailInterface {
int getMail();
}
MailTool, MailTool, :
package MailTool;
class MyMailTool implements MailInterface {
private MailTool yourMailTool;
public MyMailTool () {
yourMailTool= new MailTool();
setYourMailTool(yourMailTool);
}
public int getMail() {
return getYourMailTool().retrieveMail();
}
public MailTool getYourMailTool() {
return yourMailTool ;
}
public void setYourMailTool(MailTool newYourMailTool) {
296 15.
yourMailTool = newYourMailTool;
}
}
MailTool,
. MailInterface, -
getMail(). retrieveMail() MailTool.
,
MailTool getMail():
package MailTool;
public class Adapter
{
public static void main(String[] args)
{
MyMailTool myMailTool = new MyMailTool();
myMailTool.getMail();
}
}
getMail()
retrieveMail() MailTool. .
, , .
Adapter () ,
, .
:
Chain of response ( );
Command ();
Interpreter ();
Iterator ();
Mediator ();
Memento ();
Observer ();
State ();
Strategy ();
Template method ( );
Visitor ().
Iterator (). , .
297
Iterator ().
, .
,
. Iterator () ,
. , . Java Iterator (). ,
:
package Iterator;
import java.util.*;
public class Iterator {
public static void main(String args[]) {
// ArrayList
ArrayList<String> names = new ArrayList();
// ArrayList
names.add(new String(""));
names.add(new String(""));
names.add(new String(""));
names.add(new String(""));
//
System.out.println(":");
iterate(names );
}
private static void iterate(ArrayList<String> arl) {
for(String listItem : arl) {
System.out.println(listItem.toString());
}
}
}
, . , ,
iterate(). Java-
hasMoreElements(),
.
, .
,
. ,
(Creating Chaos), (Johnny
298 15.
Johnson), .
-, .
, . ,
, .
,
, ,
.
C++ Report 1995 (Andrew
Koenig) :
,
;
, ,
.
, ,
, .
. , , , , . ,
.
, (Reuse Patterns and Antipatterns) Robust
Artifact ( ) :
, , ,
, , . , , , ,
. Robust Artifact ( ) , .
, , , , . , ,
:
Reuseless Artifact (,
), , -. ,
, Robust Artifact (
).
, , .
299
,
.
, - .
,
, , .
. : , ,
(APattern Language: Towns, Buildings, Construction). : Oxford
University Press, 1977.
. - . (Design Patterns: Elements of Reusable Object-Oriented
Software). : Addison-Wesley, 1995.
. UML .
- , (Applying UML and Patterns: AnIntroduction to Object-Oriented
Analysis and Design and Iterative Development). 3-. : Wiley,
2004.
. Java.
, UML (Patterns in Java:
ACatalog of Reusable Design Patterns Illustrated with UML). 2-., :
Wiley, 2002. . 1.
. (Reuse
Patterns and Antipatterns) / Software Development Magazine. 2000.
. Java 2 (Java 2 Platform Unleashed).
: Sams Publishing, 1999.
. (Creating Chaos) / American Programmer.
1995.
C# .NET. Java, .
C# .NET
Counter.cs
using System;
using System.Collections.Generic;
using System.Text;
300 15.
namespace Counter
{
class Counter
{
private int counter;
private static Counter instance = null;
protected Counter()
{
}
public static Counter getInstance()
{
if (instance == null)
{
instance = new Counter();
Console.WriteLine(" Counter...");
}
return instance;
}
public void incrementCounter()
{
counter++;
}
public int getCounter()
{
return counter;
}
}
}
Singleton.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Counter
{
class Singleton
{
public Singleton()
{
Counter counter1 = Counter.getInstance();
counter1.incrementCounter();
counter1.incrementCounter();
Console.WriteLine(" = " + counter1.getCounter());
301
,
Counter counter2 = Counter.getInstance();
counter2.incrementCounter();
Console.WriteLine(" = " + counter2.getCounter());
Console.WriteLine(" , ...");
Console.ReadKey();
}
}
}
MailTool.cs
using System;
namespace MailAdapter
{
class MailTool
{
public MailTool()
{
}
public int retrieveMail()
{
Console.WriteLine(" !");
return 0;
}
}
}
Mailinterface.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace MailAdapter
{
interface MailInterface
{
int getMail();
}
}
MyMail.cs
namespace MailAdapter
{
class MyMailTool : MailInterface
{
private MailTool yourMailTool;
302 15.
public MyMailTool()
{
yourMailTool = new MailTool();
setYourMailTool(yourMailTool);
}
public int getMail()
{
return getYourMailTool().retrieveMail();
}
public MailTool getYourMailTool()
{
return yourMailTool;
}
public void setYourMailTool(MailTool newYourMailTool)
{
yourMailTool = newYourMailTool;
}
}
}
Adapter.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace MailAdapter
{
class Adapter
{
public Adapter()
{
MyMailTool myMailTool = new MyMailTool();
myMailTool.getMail();
Console.WriteLine();
Console.WriteLine(" , ...");
Console.ReadKey();
}
}
}
Iterator.cs
using
using
using
using
System;
System.Collections.Generic;
System.Text;
System.Collections;
303
,
namespace Iterator
{
class Iterator
{
public Iterator()
{
// Arraylist
ArrayList myList = new ArrayList();
//
myList.Add("");
myList.Add("");
myList.Add("");
myList.Add("");
//
Console.WriteLine(":");
iterate(myList);
}
static void iterate(ArrayList arl)
{
foreach (String listItem in arl)
{
Console.WriteLine(listItem);
}
}
}
}
.
-
.
.
.
.
. , .
.
, 192102, -, . (. ), . 3, , . 7.
005-93, 2; 95 3005 .
28.02.14. 70100/16. . . . 24,510. 1500. 0000.
. 180004, , . , 34.