about summary refs log tree commit diff
path: root/usth/ICT2.7/P4L5 Software Refactoring Subtitles/12 - Extract Class - lang_en_vs4.srt
blob: 07c93edaeadac3724661ed4ba0544f4ec7caa8d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
1
00:00:00,100 --> 00:00:02,890
We are now going to talk about the extract class refactoring. When a

2
00:00:02,890 --> 00:00:06,040
softer system evolves, we might end up with classes that really do the

3
00:00:06,040 --> 00:00:09,210
work of more than one class because we keep adding functionality to

4
00:00:09,210 --> 00:00:11,010
the class. Therefore also they're too

5
00:00:11,010 --> 00:00:13,160
big, too complicated. In particular, we might

6
00:00:13,160 --> 00:00:15,250
end up with a class that is doing the work of two

7
00:00:15,250 --> 00:00:18,890
classes. Typical examples are classes with many methods and quite a lot of

8
00:00:18,890 --> 00:00:22,520
data, quite a lot of fields. In this case, it's normally good idea

9
00:00:22,520 --> 00:00:25,120
to split the class into two, so what you will do, you will

10
00:00:25,120 --> 00:00:28,700
create a new class and move there the relevant fields and methods from

11
00:00:28,700 --> 00:00:31,700
the original class. So as to have two classes, each one implementing a

12
00:00:31,700 --> 00:00:34,900
piece of the functionality. Let's look at an example. In this case we're

13
00:00:34,900 --> 00:00:38,850
going to use a UML like representation for the class. We have this class Person

14
00:00:38,850 --> 00:00:41,769
that ends up representing also a phone number. And imagine that we add

15
00:00:41,769 --> 00:00:44,500
up these pieces, you know, a little bit at the time so we end

16
00:00:44,500 --> 00:00:47,430
up with something that really is doing the job of the person and

17
00:00:47,430 --> 00:00:50,490
of the phone number. So what we can do, we can actually do exactly

18
00:00:50,490 --> 00:00:52,650
what we described here. We split this class

19
00:00:52,650 --> 00:00:55,470
into a Person class, and the Phone Number class.

20
00:00:55,470 --> 00:00:57,440
And then we establish a use relation, so we

21
00:00:57,440 --> 00:00:59,470
have a reference of the phone number class into

22
00:00:59,470 --> 00:01:01,960
this class. And by separating the telephone number behavior

23
00:01:01,960 --> 00:01:04,680
into its own class, I once more improved the

24
00:01:04,680 --> 00:01:06,980
structure of the code, because now I have classes

25
00:01:06,980 --> 00:01:09,070
that are more cohesive, and do exactly one thing.