1 00:00:00,410 --> 00:00:01,500 This video talks about data 2 00:00:01,730 --> 00:00:04,380 modeling and UML, the Unified Modeling Language. 3 00:00:05,120 --> 00:00:06,230 The area of data modeling 4 00:00:06,780 --> 00:00:07,760 consists of how we represent 5 00:00:08,320 --> 00:00:09,340 the data for an application. 6 00:00:10,420 --> 00:00:12,680 We've talked a great length about the relational data model. 7 00:00:13,430 --> 00:00:14,730 Its widely used and we 8 00:00:14,890 --> 00:00:17,900 have good design principles for coming up with relational schemas. 9 00:00:19,200 --> 00:00:20,740 We also talked about XML as 10 00:00:20,850 --> 00:00:22,150 a data model, XML is quite 11 00:00:22,330 --> 00:00:23,510 a bit newer and there are 12 00:00:23,690 --> 00:00:25,270 no design principles that are 13 00:00:25,470 --> 00:00:27,160 analogous to the ones for the relational model. 14 00:00:28,260 --> 00:00:29,900 But frequently when people are 15 00:00:30,000 --> 00:00:31,490 designing a database, they'll actually 16 00:00:31,820 --> 00:00:33,130 use a higher level model 17 00:00:33,500 --> 00:00:35,020 that's specifically for database design. 18 00:00:35,900 --> 00:00:37,680 These models aren't implemented by 19 00:00:37,870 --> 00:00:39,910 the database system, rather they're 20 00:00:40,220 --> 00:00:42,510 translated into the model of the database system. 21 00:00:42,820 --> 00:00:44,150 So let's draw a picture of that. 22 00:00:44,700 --> 00:00:45,620 Let's suppose that we have 23 00:00:45,950 --> 00:00:47,690 a relational database management system 24 00:00:47,970 --> 00:00:50,260 which is abbreviated RDBMS often, and 25 00:00:50,360 --> 00:00:52,090 I'll draw that as a disk just out of tradition. 26 00:00:53,080 --> 00:00:54,230 So, if we create a database 27 00:00:54,600 --> 00:00:55,820 in a relational system the 28 00:00:55,920 --> 00:00:57,570 database is going to consist of relations. 29 00:00:59,130 --> 00:01:00,480 but instead of designing relations 30 00:01:01,050 --> 00:01:02,770 directly, the database designer, 31 00:01:03,270 --> 00:01:04,600 we'll draw that up here, will 32 00:01:04,810 --> 00:01:07,180 use instead a higher-level design model. 33 00:01:08,700 --> 00:01:09,780 That model will then go 34 00:01:10,020 --> 00:01:11,710 through a translator, and this 35 00:01:11,880 --> 00:01:12,900 can often be an automatic 36 00:01:13,460 --> 00:01:14,920 process that will translate the 37 00:01:15,210 --> 00:01:16,790 higher level model into the 38 00:01:17,060 --> 00:01:18,810 relations that are implemented by the database system. 39 00:01:19,930 --> 00:01:21,290 So what are these higher-level models? 40 00:01:22,230 --> 00:01:24,330 Historically, for decades in 41 00:01:24,470 --> 00:01:25,820 fact, the entity relationship 42 00:01:26,470 --> 00:01:27,660 model, also known as the 43 00:01:28,000 --> 00:01:29,770 ER model, was a very popular one. 44 00:01:30,450 --> 00:01:31,830 But more recently the unified 45 00:01:32,180 --> 00:01:33,620 modeling language has become popular 46 00:01:34,150 --> 00:01:35,330 for higher-level database design. 47 00:01:35,820 --> 00:01:37,310 The unified modeling language is 48 00:01:37,390 --> 00:01:38,440 actually a very large language, 49 00:01:38,830 --> 00:01:41,520 not just for database designs, but also for designing programs. 50 00:01:42,510 --> 00:01:43,360 So what we're going to look 51 00:01:43,670 --> 00:01:46,120 at is the data modeling subset of UML. 52 00:01:47,500 --> 00:01:48,970 Both of these design models are 53 00:01:49,090 --> 00:01:50,690 fundamentally graphical, so in 54 00:01:50,900 --> 00:01:52,060 designing a database, the user 55 00:01:52,260 --> 00:01:54,510 will draw boxes and arrows, perhaps other shapes. 56 00:01:55,550 --> 00:01:56,550 And also both of them 57 00:01:56,710 --> 00:01:59,670 can be translated, generally automatically, into relations. 58 00:02:00,830 --> 00:02:01,870 Sometimes there may be little human 59 00:02:02,210 --> 00:02:04,930 intervention in the translation process, but often that's not necessary. 60 00:02:06,150 --> 00:02:07,850 So in the data modeling subset of 61 00:02:07,950 --> 00:02:09,660 UML, there are five basic concepts. 62 00:02:10,220 --> 00:02:12,550 Classes, associations, association classes, sub-classes, and composition and aggregation. 63 00:02:12,860 --> 00:02:16,140 We're just going to go 64 00:02:16,440 --> 00:02:17,230 through each one of those 65 00:02:17,470 --> 00:02:18,920 concepts in turn with examples. 66 00:02:20,440 --> 00:02:21,820 So that class concept in UML 67 00:02:22,370 --> 00:02:23,750 is not specific to data-modeling. 68 00:02:23,910 --> 00:02:25,630 It's also used for designing programs. 69 00:02:26,690 --> 00:02:28,270 The class consists of a 70 00:02:28,340 --> 00:02:29,870 name for the class, attributes of 71 00:02:29,940 --> 00:02:31,160 the class, and methods in the 72 00:02:31,240 --> 00:02:33,510 class, and that's probably familiar to you again from programming. 73 00:02:34,590 --> 00:02:36,490 For data modeling specifically, we 74 00:02:36,970 --> 00:02:38,270 add to the attributes the 75 00:02:38,340 --> 00:02:40,440 concept of a primary key, 76 00:02:40,620 --> 00:02:41,690 and we drop the methods 77 00:02:42,150 --> 00:02:43,550 that are associated since we're focusing, 78 00:02:44,370 --> 00:02:45,840 really, on the data modeling at this point. 79 00:02:46,890 --> 00:02:47,900 So we'll be drawing our examples, 80 00:02:48,320 --> 00:02:49,970 as usual, from a imaginary 81 00:02:50,650 --> 00:02:52,430 college admissions database with 82 00:02:52,560 --> 00:02:55,300 students and colleges and students applying to colleges and so forth. 83 00:02:55,980 --> 00:02:57,460 So one of our classes, not 84 00:02:57,700 --> 00:02:59,310 surprisingly, will be the student class. 85 00:02:59,750 --> 00:03:01,120 And in UML we'll draw a 86 00:03:01,380 --> 00:03:02,730 class as a box 87 00:03:03,020 --> 00:03:04,410 like this, and at the 88 00:03:04,480 --> 00:03:05,350 top we put the name 89 00:03:05,820 --> 00:03:07,140 of the class and then we 90 00:03:07,400 --> 00:03:08,530 put the attributes of the class, 91 00:03:08,750 --> 00:03:10,670 so let's suppose that we'll just keep it simple. 92 00:03:11,050 --> 00:03:12,420 We'll have a student ID, a 93 00:03:13,150 --> 00:03:14,850 student name, and for 94 00:03:14,960 --> 00:03:17,360 now, the student's GPA and 95 00:03:17,550 --> 00:03:18,800 down here in UML would 96 00:03:19,000 --> 00:03:20,680 be the specification of the methods. 97 00:03:21,420 --> 00:03:22,640 Again we're not going to 98 00:03:22,710 --> 00:03:23,820 be focusing on methods since we 99 00:03:23,930 --> 00:03:26,950 are looking at data-modeling,and not the operations on the data. 100 00:03:27,840 --> 00:03:29,440 And so one difference is that we'll have no methods. 101 00:03:29,890 --> 00:03:30,910 Another is that we specify 102 00:03:31,570 --> 00:03:32,780 a primary key if we 103 00:03:32,920 --> 00:03:34,400 wish and that's specified 104 00:03:35,010 --> 00:03:36,480 using the terminology PK. 105 00:03:37,180 --> 00:03:40,010 So we'll say that the student ID in this case is the primary key. 106 00:03:40,840 --> 00:03:41,890 And just as in keys in 107 00:03:42,000 --> 00:03:43,200 the relational model, that means 108 00:03:43,430 --> 00:03:44,530 that when we have a set 109 00:03:44,740 --> 00:03:45,830 of objects for the student 110 00:03:46,230 --> 00:03:49,120 class, each object will have a unique student ID. 111 00:03:49,310 --> 00:03:51,660 There will be no student IDs repeated across objects. 112 00:03:53,000 --> 00:03:54,770 in our college application database, we're 113 00:03:54,900 --> 00:03:55,940 also likely to have a 114 00:03:56,000 --> 00:03:58,790 class for colleges, so we'll have a class that we call college. 115 00:03:59,870 --> 00:04:01,000 And for now, we'll make 116 00:04:01,270 --> 00:04:02,320 the attributes of that 117 00:04:02,840 --> 00:04:05,680 class, just the college name and the state. 118 00:04:08,110 --> 00:04:10,610 And again in full UML, there might be some methods down here. 119 00:04:11,250 --> 00:04:12,710 And we'll make the college 120 00:04:13,170 --> 00:04:14,700 name and this case be the primary key. 121 00:04:14,940 --> 00:04:17,630 So we're assuming now that college names themselves are unique. 122 00:04:18,470 --> 00:04:19,510 So that's it for classes. 123 00:04:20,200 --> 00:04:21,380 Pretty straightforward, they look a 124 00:04:21,530 --> 00:04:22,800 lot like relations and of 125 00:04:22,910 --> 00:04:24,600 course, they will translate directly to relations. 126 00:04:25,680 --> 00:04:26,620 Next let's talk about associations. 127 00:04:28,610 --> 00:04:32,070 Associations capture relationships between objects of two different classes. 128 00:04:32,980 --> 00:04:34,310 So lets suppose again that 129 00:04:34,390 --> 00:04:35,920 we have our student class and 130 00:04:36,260 --> 00:04:37,530 I won't write the attributes now, 131 00:04:37,690 --> 00:04:38,550 I'll just write it like that 132 00:04:39,310 --> 00:04:40,880 and we have our college class 133 00:04:41,810 --> 00:04:42,890 in our UML design. 134 00:04:44,070 --> 00:04:45,300 If we want to have a 135 00:04:45,350 --> 00:04:47,480 relationship that students apply 136 00:04:47,960 --> 00:04:49,530 to colleges, we write that 137 00:04:49,730 --> 00:04:51,120 just as a line between 138 00:04:51,750 --> 00:04:52,760 the students and the college classes 139 00:04:53,450 --> 00:04:54,500 and then we give it a name. 140 00:04:54,910 --> 00:04:55,960 So we'll call it applied 141 00:04:56,970 --> 00:04:58,250 and that says that we have 142 00:04:58,810 --> 00:05:00,150 objects in the student class and 143 00:05:00,240 --> 00:05:01,150 objects that are in the college class 144 00:05:01,590 --> 00:05:02,780 that are associated with each 145 00:05:02,990 --> 00:05:04,580 other through the applied association. 146 00:05:05,970 --> 00:05:07,240 If we want to introduce a 147 00:05:07,290 --> 00:05:08,490 directionality to the relationship, 148 00:05:09,160 --> 00:05:10,840 so to say that student are 149 00:05:10,950 --> 00:05:12,100 applying to colleges, we can 150 00:05:12,250 --> 00:05:13,280 put in a arrow there, 151 00:05:13,480 --> 00:05:14,430 that's part of the UML language 152 00:05:15,180 --> 00:05:15,970 although we'll see that it doesn't 153 00:05:16,380 --> 00:05:17,670 really make much difference when we 154 00:05:17,830 --> 00:05:19,840 end up translating UML designs to relations. 155 00:05:21,340 --> 00:05:23,210 When we have associations between classes, 156 00:05:23,810 --> 00:05:25,070 we can specify what we call 157 00:05:25,310 --> 00:05:27,030 the multiplicity of those and 158 00:05:27,360 --> 00:05:28,710 that talks about how many objects 159 00:05:29,220 --> 00:05:30,180 of one class can be related 160 00:05:30,620 --> 00:05:31,830 to an object of another class. 161 00:05:32,240 --> 00:05:33,230 So we'll see that we 162 00:05:33,320 --> 00:05:34,730 can capture concepts like one-one 163 00:05:35,250 --> 00:05:36,290 and many-one and so forth. 164 00:05:37,070 --> 00:05:38,750 So let's look specifically at 165 00:05:38,810 --> 00:05:40,480 how we specify those in 166 00:05:40,610 --> 00:05:42,100 a UML diagram, and for 167 00:05:42,220 --> 00:05:43,960 now I'll just use two generic classes. 168 00:05:44,420 --> 00:05:45,120 So let's say I have a 169 00:05:45,330 --> 00:05:47,200 class C1 and I 170 00:05:47,390 --> 00:05:49,830 have a class C2, and let's 171 00:05:50,240 --> 00:05:50,920 say that I have an association 172 00:05:51,820 --> 00:05:54,500 between those two classes, so that would be a line. 173 00:05:54,800 --> 00:05:55,590 And I could give that a name, 174 00:05:56,480 --> 00:05:58,650 let's call it A. Let's say 175 00:05:58,900 --> 00:06:00,640 that I want to specify that 176 00:06:01,260 --> 00:06:02,300 each object in Class C, 177 00:06:02,450 --> 00:06:03,310 well I'm just going to write those 178 00:06:03,470 --> 00:06:05,640 objects kind of as dots here below the class specification. 179 00:06:06,130 --> 00:06:07,130 Let's say that I 180 00:06:07,270 --> 00:06:08,310 wanted to say that each one 181 00:06:08,550 --> 00:06:09,650 of those is going to 182 00:06:09,760 --> 00:06:11,240 be related to at least 183 00:06:11,950 --> 00:06:12,950 M but at most 184 00:06:13,570 --> 00:06:14,690 N objects in class 185 00:06:15,100 --> 00:06:17,070 C2, so here are class C2 objects. 186 00:06:17,450 --> 00:06:19,930 I'm going to have this kind of fan out in my relationship. 187 00:06:21,220 --> 00:06:21,990 To specify that in the 188 00:06:22,570 --> 00:06:25,450 UML diagram I write that as M.. 189 00:06:26,340 --> 00:06:28,620 and on the right side 190 00:06:29,380 --> 00:06:31,040 of the association line and 191 00:06:31,140 --> 00:06:32,310 again that's say each object 192 00:06:32,820 --> 00:06:34,300 then in C1, then will related 193 00:06:34,990 --> 00:06:38,560 to between M and N objects of C2. 194 00:06:40,050 --> 00:06:41,890 Now there are some special cases in this notation. 195 00:06:42,530 --> 00:06:43,950 I can write M dot dot 196 00:06:44,310 --> 00:06:45,870 star, and star means 197 00:06:46,350 --> 00:06:47,590 any number of objects, so 198 00:06:47,790 --> 00:06:48,790 what that would see is 199 00:06:49,050 --> 00:06:50,360 that each object in "C1" 200 00:06:50,780 --> 00:06:51,700 is related to atleast "M" 201 00:06:52,640 --> 00:06:54,930 and, as many as it wants, elements of "C2". 202 00:06:56,130 --> 00:06:58,070 I can also write zero to 203 00:06:58,450 --> 00:06:59,710 end and that will 204 00:06:59,910 --> 00:07:01,170 say that each object in C1 205 00:07:01,540 --> 00:07:03,080 is related to possibly none 206 00:07:03,680 --> 00:07:04,690 for example here we have one 207 00:07:04,860 --> 00:07:06,300 that I haven't draw any relations tips. 208 00:07:06,830 --> 00:07:09,240 Possibly none and up to N elements of C2. 209 00:07:10,560 --> 00:07:11,960 I can also write zero dot 210 00:07:12,300 --> 00:07:13,600 dot star, and that's basic 211 00:07:14,090 --> 00:07:15,990 no restrictions on the multiplicity. 212 00:07:17,220 --> 00:07:18,530 And just to mention, 213 00:07:19,140 --> 00:07:21,950 the default, actually, is one dot dot one. 214 00:07:22,670 --> 00:07:23,900 So if we don't write anything 215 00:07:24,270 --> 00:07:26,310 on our association we're 216 00:07:26,520 --> 00:07:27,960 assuming that each object is 217 00:07:28,080 --> 00:07:29,350 related to exactly one object 218 00:07:29,760 --> 00:07:30,960 of the other class and that's in 219 00:07:31,090 --> 00:07:32,300 both directions by the way, 220 00:07:32,760 --> 00:07:34,600 so I can put a X.. 221 00:07:34,880 --> 00:07:35,930 Y here and now we'll 222 00:07:36,160 --> 00:07:38,310 restrict how many objects of 223 00:07:38,720 --> 00:07:40,580 element of C2 is related to. 224 00:07:41,660 --> 00:07:44,570 Incidentally UML allow some abbreviations, 1..1 225 00:07:45,720 --> 00:07:46,930 can be abbreviated as a just 226 00:07:47,270 --> 00:07:49,310 plain old one and 0.. 227 00:07:49,770 --> 00:07:51,610 can be abbreviated with just star. 228 00:07:52,950 --> 00:07:53,780 So let's take a look at 229 00:07:53,850 --> 00:07:55,360 our student and college example and 230 00:07:55,470 --> 00:07:56,960 what the multiplicity of the association 231 00:07:57,830 --> 00:07:59,450 of students applying to colleges might be. 232 00:08:00,170 --> 00:08:01,530 So let's suppose that we 233 00:08:01,810 --> 00:08:03,250 insist that students must apply 234 00:08:03,610 --> 00:08:04,540 somewhere, so they apply to at 235 00:08:04,640 --> 00:08:06,420 least one college but they're 236 00:08:06,690 --> 00:08:07,810 not allow to apply to more 237 00:08:08,000 --> 00:08:09,550 than 5 and further more 238 00:08:09,840 --> 00:08:11,230 lets say that no college will 239 00:08:11,380 --> 00:08:13,630 take more than 20,000 applications, so 240 00:08:13,820 --> 00:08:15,250 this example is contrived to 241 00:08:15,340 --> 00:08:18,020 allow me to put multiplicity specifications on both sides. 242 00:08:18,810 --> 00:08:19,890 So again, we'll have our 243 00:08:20,420 --> 00:08:22,520 student class and we'll 244 00:08:22,780 --> 00:08:24,290 have our college class 245 00:08:25,430 --> 00:08:27,270 and we'll have our association 246 00:08:28,570 --> 00:08:30,020 between the student and the 247 00:08:30,230 --> 00:08:32,420 college class, and I'll just write the name underneath here. 248 00:08:32,690 --> 00:08:33,050 Now applied. 249 00:08:34,190 --> 00:08:35,230 So lets think about how 250 00:08:35,390 --> 00:08:37,280 to specify our multiplicities for this. 251 00:08:38,520 --> 00:08:39,720 So to specify that a student 252 00:08:39,850 --> 00:08:41,280 must apply somewhere but cannot 253 00:08:41,620 --> 00:08:42,740 apply to more than 5 254 00:08:43,040 --> 00:08:43,920 colleges, we put a one 255 00:08:44,200 --> 00:08:45,700 dot dot five on this side. 256 00:08:46,240 --> 00:08:47,420 It really takes some thinking sometimes 257 00:08:48,050 --> 00:08:50,440 to remember which side to put the specification on. 258 00:08:50,680 --> 00:08:51,750 But that's what gives us the 259 00:08:51,810 --> 00:08:53,670 fan out from the objects 260 00:08:53,980 --> 00:08:55,290 on the left to the objects on the right. 261 00:08:55,540 --> 00:08:56,770 So it says each student can 262 00:08:57,590 --> 00:08:58,650 apply to up to five 263 00:08:58,870 --> 00:09:00,120 colleges and must apply 264 00:09:00,480 --> 00:09:01,520 to at least one, so we 265 00:09:01,680 --> 00:09:03,140 won't have any who haven't applied anywhere. 266 00:09:04,260 --> 00:09:05,490 On the other side, we want 267 00:09:05,810 --> 00:09:06,890 to talk about how many students 268 00:09:07,400 --> 00:09:08,420 can have applied to a particular 269 00:09:08,940 --> 00:09:11,540 college, and we said it can be no more than 20,000. 270 00:09:11,680 --> 00:09:13,180 We didn't put a lower 271 00:09:13,390 --> 00:09:14,360 restriction on that, so we 272 00:09:14,510 --> 00:09:16,860 would specify that as 0 to 20,000. 273 00:09:19,050 --> 00:09:20,300 So I mentioned earlier that multiplicity 274 00:09:20,990 --> 00:09:22,780 of associations captures some of 275 00:09:22,840 --> 00:09:24,180 these types of relationships you might 276 00:09:24,360 --> 00:09:25,620 have learned about somewhere else called 277 00:09:25,850 --> 00:09:28,010 one to one, many to one, and so on. 278 00:09:28,180 --> 00:09:29,350 So, let me show the relationship 279 00:09:30,020 --> 00:09:34,540 between association multiplicity and this terminology. 280 00:09:36,340 --> 00:09:38,020 So if we have a one-to-one relationship 281 00:09:39,130 --> 00:09:41,220 between "C1" and "C2," technically one-to-one 282 00:09:41,880 --> 00:09:43,320 doesn't mean everything has to be involved. 283 00:09:43,920 --> 00:09:44,850 What it really means is that 284 00:09:45,100 --> 00:09:46,630 each object on each side 285 00:09:46,990 --> 00:09:48,800 is related to at most one on the other side. 286 00:09:49,480 --> 00:09:50,810 So to say it's a one-to-one relationship 287 00:09:51,490 --> 00:09:52,650 we would put a "zero, dot, 288 00:09:52,940 --> 00:09:54,420 dot, one" on both sides. 289 00:09:55,610 --> 00:09:57,020 Let's see if I can use some colors here. 290 00:09:57,470 --> 00:09:58,000 So what about many-to-one? 291 00:09:59,330 --> 00:10:00,220 Many-to-one says that we can have 292 00:10:00,360 --> 00:10:02,000 many elements of "C1" related 293 00:10:02,450 --> 00:10:03,630 to an element of "C2," but 294 00:10:03,800 --> 00:10:05,020 each element of "C2" will 295 00:10:05,310 --> 00:10:07,740 be related to, at most, one element of "C1." 296 00:10:08,940 --> 00:10:09,830 So in that case we still 297 00:10:10,070 --> 00:10:11,280 have a "zero, dot, dot, one" 298 00:10:11,530 --> 00:10:13,310 on the right side indicating that 299 00:10:13,550 --> 00:10:14,850 each "C1" object is related 300 00:10:15,230 --> 00:10:16,840 to at most one object of 301 00:10:16,940 --> 00:10:18,310 "C2" but we have the 302 00:10:18,480 --> 00:10:19,560 star on the left hand 303 00:10:19,840 --> 00:10:21,550 side indicating that C2 objects 304 00:10:22,070 --> 00:10:23,130 can be related to any number 305 00:10:23,550 --> 00:10:25,110 of "C1" objects and, as 306 00:10:25,130 --> 00:10:26,270 a reminder, star is an abbreviation 307 00:10:26,990 --> 00:10:28,010 for "zero, dot, dot, star." 308 00:10:29,200 --> 00:10:31,010 Many to many has no 309 00:10:31,290 --> 00:10:32,700 restrictions on the relationships. 310 00:10:33,330 --> 00:10:35,110 So that would be a star on both sides. 311 00:10:35,570 --> 00:10:37,600 Pretty simple and the last 312 00:10:37,980 --> 00:10:40,080 concept is the idea of complete relationships. 313 00:10:40,760 --> 00:10:43,990 So a complete relationship is complementary to these others. 314 00:10:44,660 --> 00:10:46,180 It says that every object 315 00:10:46,530 --> 00:10:48,080 must participate in the relationship. 316 00:10:49,010 --> 00:10:50,150 So we can have a complete one 317 00:10:50,470 --> 00:10:51,460 to one, and that would 318 00:10:51,570 --> 00:10:53,280 be one dot dot one on both sides. 319 00:10:54,140 --> 00:10:55,880 We could have a complete many to 320 00:10:56,100 --> 00:10:57,390 one, and that would 321 00:10:57,570 --> 00:10:58,600 be on the left side 322 00:10:58,880 --> 00:11:00,260 one dot dot star, and 323 00:11:00,350 --> 00:11:01,660 on the right side one dot dot 324 00:11:02,060 --> 00:11:03,130 one and, finally, a complete 325 00:11:03,740 --> 00:11:04,810 many to many would be 326 00:11:04,960 --> 00:11:06,940 one dot dot star on each side. 327 00:11:07,670 --> 00:11:09,560 As a reminder, the default if 328 00:11:09,720 --> 00:11:10,900 we don't specify the multiplicity 329 00:11:11,970 --> 00:11:14,460 is a one dot dot one both sides. 330 00:11:14,900 --> 00:11:16,260 So that would be a complete 331 00:11:16,950 --> 00:11:17,930 one to one relationship. 332 00:11:19,750 --> 00:11:21,350 Ok, we've finished with classes and with associations. 333 00:11:22,190 --> 00:11:23,820 Now let's talk about association classes. 334 00:11:25,280 --> 00:11:27,090 Association classes generalize the 335 00:11:27,170 --> 00:11:28,620 notion of associations by allowing 336 00:11:29,100 --> 00:11:30,600 us to put attributes on the 337 00:11:30,730 --> 00:11:33,570 association itself and, again, we'll use our example. 338 00:11:35,360 --> 00:11:36,220 So we already knew how to 339 00:11:36,300 --> 00:11:37,920 specify that students apply to 340 00:11:38,270 --> 00:11:39,880 colleges, but what if associated 341 00:11:40,270 --> 00:11:41,420 with the application we wanted 342 00:11:41,810 --> 00:11:42,840 to have, for example, the date 343 00:11:43,210 --> 00:11:45,340 that they applied and maybe the decision of that application. 344 00:11:46,550 --> 00:11:47,330 We don't really have a way 345 00:11:47,470 --> 00:11:48,500 to do that without adding a 346 00:11:48,620 --> 00:11:50,290 new construct, and that construct 347 00:11:50,700 --> 00:11:52,320 is what's known as an association class. 348 00:11:53,050 --> 00:11:55,630 So we can make a class and we'll just call it "App Info". 349 00:11:56,450 --> 00:11:57,260 And it looks like a class, 350 00:11:57,720 --> 00:12:00,350 it's got the box with the name at the top and the attributes. 351 00:12:01,020 --> 00:12:02,590 And then we just attach that 352 00:12:02,780 --> 00:12:04,290 box to the association, 353 00:12:05,540 --> 00:12:06,650 and that tells us 354 00:12:06,800 --> 00:12:08,470 that each instance of 355 00:12:08,650 --> 00:12:09,710 the association between a student 356 00:12:10,060 --> 00:12:11,440 and a college has additional information, 357 00:12:12,110 --> 00:12:14,690 a date of that application and the decision of that application. 358 00:12:16,320 --> 00:12:17,590 Now there's a couple of things I want to mention. 359 00:12:17,810 --> 00:12:18,940 First of all, in a number 360 00:12:19,150 --> 00:12:20,710 of examples, I'll probably leave 361 00:12:21,090 --> 00:12:24,350 out the multiplicities on the ends of the associations. 362 00:12:25,560 --> 00:12:27,610 That doesn't mean I'm assuming the default one one. 363 00:12:27,900 --> 00:12:30,670 It's just when it's not relevant, I'm not going to focus on that aspect. 364 00:12:31,390 --> 00:12:33,910 Now when we have students associated with colleges. 365 00:12:34,530 --> 00:12:36,240 So we have a student here we have a college. 366 00:12:36,960 --> 00:12:39,600 Then we have an association between those. 367 00:12:40,280 --> 00:12:41,280 Now what we're saying is that 368 00:12:41,530 --> 00:12:42,840 association is going to 369 00:12:42,950 --> 00:12:45,800 have affiliated with it a date and a decision. 370 00:12:46,760 --> 00:12:48,730 What we cannot describe in 371 00:12:48,900 --> 00:12:50,000 UML is the possibility 372 00:12:51,020 --> 00:12:52,190 of having more than one 373 00:12:53,220 --> 00:12:55,170 relationship or association between the 374 00:12:55,250 --> 00:12:56,730 same student and the same college. 375 00:12:57,590 --> 00:12:58,400 So when we have an association 376 00:12:59,160 --> 00:13:00,540 that assumes at most one 377 00:13:00,950 --> 00:13:02,220 relationship between two objects. 378 00:13:03,130 --> 00:13:04,830 So, for example, if we 379 00:13:05,080 --> 00:13:06,380 wanted to add the possibility 380 00:13:07,200 --> 00:13:08,810 that students could apply to 381 00:13:08,880 --> 00:13:11,180 the same college multiple times so 382 00:13:11,270 --> 00:13:11,990 maybe you know that want 383 00:13:12,190 --> 00:13:13,620 to apply for separate majors. 384 00:13:15,260 --> 00:13:16,640 That would actually have to be captured quite differently. 385 00:13:17,080 --> 00:13:18,820 We'd have to add a separate 386 00:13:19,820 --> 00:13:21,020 class that would for the 387 00:13:21,170 --> 00:13:22,800 application information with separate 388 00:13:23,170 --> 00:13:24,430 relationships to the students and colleges. 389 00:13:24,870 --> 00:13:25,950 So this is a, in my 390 00:13:26,170 --> 00:13:28,260 mind, a slight deficiency of UML. 391 00:13:28,860 --> 00:13:30,100 Again, that and it only 392 00:13:30,470 --> 00:13:31,990 captures, at most, one relationship 393 00:13:32,630 --> 00:13:33,730 between the two specific 394 00:13:34,410 --> 00:13:35,680 objects across the two classes. 395 00:13:37,190 --> 00:13:38,160 Now, sometimes we can make 396 00:13:38,330 --> 00:13:39,500 a design that has an association 397 00:13:40,260 --> 00:13:41,210 class and it turns out 398 00:13:41,350 --> 00:13:42,360 we didn't really need it and 399 00:13:42,580 --> 00:13:43,850 we're going to come back to 400 00:13:44,090 --> 00:13:45,180 multiplicities to see how this 401 00:13:45,380 --> 00:13:47,250 can happen, so again let's 402 00:13:47,480 --> 00:13:50,180 take a look at just generic classes C1 and C2. 403 00:13:51,650 --> 00:13:52,980 Let's say that we have an 404 00:13:53,340 --> 00:13:56,300 association between them and then we have an association class. 405 00:13:56,680 --> 00:13:57,390 We'll just call it AC. 406 00:13:58,910 --> 00:13:59,810 And that's gonna have some 407 00:14:00,160 --> 00:14:02,180 attributes, we can call them A1 and A2 for now. 408 00:14:02,520 --> 00:14:03,470 And of course, there's attributes 409 00:14:04,190 --> 00:14:05,690 in C1 and C2 as well. 410 00:14:07,010 --> 00:14:08,500 Let's suppose that the multiplicity 411 00:14:09,720 --> 00:14:10,920 on, let's say the left 412 00:14:11,170 --> 00:14:12,930 side is star so anything 413 00:14:13,330 --> 00:14:14,080 goes, and on the right 414 00:14:14,400 --> 00:14:15,750 side we have one to one. 415 00:14:17,030 --> 00:14:18,610 So what that multiplicity says is 416 00:14:18,670 --> 00:14:20,540 that each object Of C1 417 00:14:21,240 --> 00:14:24,350 is related to at most one object of C2. 418 00:14:25,510 --> 00:14:27,850 So, actually exactly one object in this case. 419 00:14:28,560 --> 00:14:29,550 So we know that there's 420 00:14:29,690 --> 00:14:31,810 going to be just one association for 421 00:14:32,000 --> 00:14:33,000 each object of C1, and 422 00:14:33,080 --> 00:14:34,140 if there's only going to 423 00:14:34,190 --> 00:14:36,510 be one association actually we 424 00:14:36,580 --> 00:14:37,890 could take these attributes and we 425 00:14:37,980 --> 00:14:39,360 could put those attributes as part 426 00:14:39,630 --> 00:14:41,010 of C1 instead of having 427 00:14:41,300 --> 00:14:43,670 a separate association class, so 428 00:14:43,900 --> 00:14:45,220 for example If this class 429 00:14:45,690 --> 00:14:47,080 happened to be the student class, 430 00:14:47,500 --> 00:14:48,790 and this was the college class, 431 00:14:49,810 --> 00:14:51,160 and we insisted that each 432 00:14:51,350 --> 00:14:52,850 student apply to exactly one 433 00:14:53,130 --> 00:14:54,860 college then the attributes 434 00:14:55,280 --> 00:14:56,470 we had down here, the date 435 00:14:56,850 --> 00:14:58,380 and decision, could be moved 436 00:14:58,640 --> 00:15:00,130 into the student class, because we 437 00:15:00,240 --> 00:15:01,350 know they're only applying to one 438 00:15:01,620 --> 00:15:02,410 college, so that would be 439 00:15:02,570 --> 00:15:03,600 the date and the decision for 440 00:15:03,730 --> 00:15:05,200 the one college they're applying to. 441 00:15:06,130 --> 00:15:07,580 Furthermore, if we had zero 442 00:15:08,000 --> 00:15:08,900 dot dot one, we can 443 00:15:09,370 --> 00:15:10,820 still move these attributes here 444 00:15:11,450 --> 00:15:12,920 and, in that case, if a 445 00:15:13,240 --> 00:15:14,410 student was not involved in a 446 00:15:14,450 --> 00:15:15,510 college - had not applied 447 00:15:15,830 --> 00:15:16,850 to a college at all or, more 448 00:15:17,030 --> 00:15:18,230 generally, an object of "C1" 449 00:15:18,440 --> 00:15:19,680 was not related to any 450 00:15:19,950 --> 00:15:20,770 object of "C2" then those 451 00:15:21,660 --> 00:15:22,580 attributes would have the equivalent 452 00:15:23,240 --> 00:15:24,460 of null values in them. 453 00:15:25,350 --> 00:15:26,710 By the way, it is possible for 454 00:15:27,110 --> 00:15:29,610 an association to be between a class and itself. 455 00:15:30,650 --> 00:15:31,750 For example, we could have 456 00:15:31,940 --> 00:15:33,580 our student class and maybe 457 00:15:33,940 --> 00:15:34,640 we're going to have an association 458 00:15:35,460 --> 00:15:37,320 called "sibling", a student 459 00:15:37,750 --> 00:15:39,010 being associated with another student 460 00:15:39,340 --> 00:15:40,760 because they're siblings, an association 461 00:15:41,580 --> 00:15:42,440 between a class in itself 462 00:15:42,900 --> 00:15:44,120 is written with a line tgat 463 00:15:44,260 --> 00:15:46,200 just goes between the class and itself. 464 00:15:47,050 --> 00:15:48,150 And then we could label that sibling. 465 00:15:49,470 --> 00:15:50,660 And for multiplicities we can 466 00:15:50,910 --> 00:15:52,500 assume that every student 467 00:15:52,870 --> 00:15:53,830 has between 0 and an 468 00:15:54,200 --> 00:15:55,600 arbitrary number of siblings lets 469 00:15:55,820 --> 00:15:56,700 say, so we can put 470 00:15:56,870 --> 00:15:58,630 a star on both ends of that association. 471 00:15:59,840 --> 00:16:01,910 A more interesting association might 472 00:16:02,280 --> 00:16:03,960 involve colleges where say 473 00:16:04,220 --> 00:16:05,360 we have for every college 474 00:16:06,070 --> 00:16:07,830 a flagship main campus. 475 00:16:08,800 --> 00:16:10,230 But then some colleges have separate 476 00:16:10,590 --> 00:16:12,770 branch or satellite campuses, so 477 00:16:13,310 --> 00:16:14,730 that would be an association 478 00:16:15,960 --> 00:16:17,430 between a college and itself 479 00:16:18,290 --> 00:16:19,820 saying that one college is 480 00:16:19,990 --> 00:16:21,640 a branch of another college. 481 00:16:22,460 --> 00:16:24,220 Now let's think about the multiplicities here. 482 00:16:24,530 --> 00:16:25,470 First of all, when we 483 00:16:26,090 --> 00:16:27,790 have a self association, in UML 484 00:16:28,200 --> 00:16:30,560 we're allowed to label the two ends of the association. 485 00:16:31,630 --> 00:16:32,950 So I could, for example, say 486 00:16:33,220 --> 00:16:34,810 on one end we have the 487 00:16:36,260 --> 00:16:37,780 home campus. 488 00:16:38,330 --> 00:16:40,010 And on another end we have the satellite campus. 489 00:16:41,100 --> 00:16:42,190 And now with those labels 490 00:16:42,730 --> 00:16:43,890 we can see the asymmetry and 491 00:16:44,040 --> 00:16:45,820 that lets us get our associations right. 492 00:16:46,840 --> 00:16:48,100 So let's say that every satellite 493 00:16:48,790 --> 00:16:50,400 campus must have exactly one 494 00:16:50,690 --> 00:16:51,810 home campus, so that would 495 00:16:51,940 --> 00:16:53,360 be a one dot dot here 496 00:16:54,270 --> 00:16:55,640 and every home campus can have 497 00:16:56,360 --> 00:16:57,710 any number of satellite campuses. 498 00:16:58,210 --> 00:16:59,780 Or actually, let's say something else. 499 00:16:59,940 --> 00:17:00,870 Let's say every home campus 500 00:17:01,630 --> 00:17:03,110 can have between zero and ten 501 00:17:03,450 --> 00:17:05,550 satellite campuses be a 502 00:17:05,810 --> 00:17:08,240 zero dot dot ten on that side of the self association. 503 00:17:09,800 --> 00:17:10,720 Ok, we're finished with the first 504 00:17:10,960 --> 00:17:12,830 three let's move on to sub classes. 505 00:17:14,230 --> 00:17:15,180 For sub classes we're gonna do 506 00:17:15,300 --> 00:17:16,650 a fairly large example that involves 507 00:17:17,110 --> 00:17:18,060 students that we're gonna 508 00:17:18,200 --> 00:17:20,330 separate into foreign students and domestic students. 509 00:17:21,170 --> 00:17:22,650 We're also going to separately specify 510 00:17:23,210 --> 00:17:24,540 students who have taken AP 511 00:17:25,040 --> 00:17:27,020 classes and those will be our AP students. 512 00:17:27,890 --> 00:17:28,510 So we're going to have the student 513 00:17:28,990 --> 00:17:30,660 class as the top 514 00:17:31,290 --> 00:17:32,580 of our hierarchy and the 515 00:17:32,650 --> 00:17:34,230 student class will, again, have 516 00:17:34,520 --> 00:17:36,610 the student ID, let's say 517 00:17:36,770 --> 00:17:38,280 the student name, and GPA, 518 00:17:39,130 --> 00:17:40,260 and we'll say the the student 519 00:17:40,520 --> 00:17:41,860 ID is the primary key for 520 00:17:41,990 --> 00:17:44,090 objects in that class, we're 521 00:17:44,340 --> 00:17:45,550 going to have three sub classes, 522 00:17:46,150 --> 00:17:47,100 one is going to be the 523 00:17:47,260 --> 00:17:48,450 foreign students, we'll call it 524 00:17:48,660 --> 00:17:50,070 foreign S, one is going 525 00:17:50,150 --> 00:17:51,970 to be the domestic students and 526 00:17:52,280 --> 00:17:53,320 then we're also going to 527 00:17:53,490 --> 00:17:55,410 have a sub class for AP students. 528 00:17:56,850 --> 00:17:58,080 and I'm going to assume that 529 00:17:58,220 --> 00:18:00,570 you already know a little bit about sub classing from programming. 530 00:18:01,380 --> 00:18:02,620 So the idea is that when 531 00:18:03,050 --> 00:18:04,390 we have a sub class, 532 00:18:05,080 --> 00:18:06,690 there are attributes that are 533 00:18:06,780 --> 00:18:08,010 specific to the objects 534 00:18:08,360 --> 00:18:09,520 that are in that sub class 535 00:18:10,200 --> 00:18:12,500 and they'll inherit the attributes from their super class. 536 00:18:13,240 --> 00:18:15,450 So we're gonna make student be a super class here. 537 00:18:15,740 --> 00:18:16,870 And this is how we draw it, 538 00:18:17,340 --> 00:18:19,120 with three sub classes here 539 00:18:19,370 --> 00:18:21,630 for foreign student, domestic student, and AP student. 540 00:18:22,710 --> 00:18:24,170 And we'll say that foreign students 541 00:18:24,630 --> 00:18:25,920 have in addition to a 542 00:18:25,980 --> 00:18:27,200 student ID, a student name and 543 00:18:27,320 --> 00:18:29,150 GPA, a country that they come from. 544 00:18:29,970 --> 00:18:31,460 We'll say that Domestic students 545 00:18:31,920 --> 00:18:32,820 are going to have a state 546 00:18:33,430 --> 00:18:34,280 that they come from and we'll 547 00:18:34,420 --> 00:18:35,300 also say that they have 548 00:18:35,490 --> 00:18:36,900 a Social Security number, which we 549 00:18:36,980 --> 00:18:38,860 don't know that foreign students would necessarily have. 550 00:18:40,440 --> 00:18:43,160 AP students, interestingly, is going to be empty. 551 00:18:43,300 --> 00:18:44,400 It's not going to have any 552 00:18:44,690 --> 00:18:46,960 additional attributes, but 553 00:18:47,360 --> 00:18:48,710 the AP students are the 554 00:18:48,800 --> 00:18:49,780 students that are going to 555 00:18:49,850 --> 00:18:51,060 be allowed to have a 556 00:18:51,620 --> 00:18:53,060 relationship with AP courses. 557 00:18:54,960 --> 00:18:55,890 We'll say that the 558 00:18:55,960 --> 00:18:57,360 AP course has a course number 559 00:18:57,660 --> 00:18:59,330 and that's probably the primary key. 560 00:18:59,770 --> 00:19:02,620 And maybe a title for the course and some units for the course. 561 00:19:03,700 --> 00:19:05,840 And then when one of our AP students takes the course. 562 00:19:06,240 --> 00:19:07,970 We'll call this "Association took". 563 00:19:08,630 --> 00:19:09,930 We're going to have an association class 564 00:19:10,420 --> 00:19:11,520 that goes along with that, that's 565 00:19:11,740 --> 00:19:13,090 going to have the information, 566 00:19:13,790 --> 00:19:15,560 let's called it "AP info", about 567 00:19:16,270 --> 00:19:17,770 them taking that particular AP 568 00:19:18,070 --> 00:19:19,480 class and we'll say that 569 00:19:19,880 --> 00:19:21,560 association class has for 570 00:19:21,790 --> 00:19:22,890 example the year that they 571 00:19:23,050 --> 00:19:25,300 took the class and maybe the grade that they got in the class. 572 00:19:26,650 --> 00:19:28,030 And lastly let's add some multiplicities. 573 00:19:28,900 --> 00:19:30,450 Let's say that AP students 574 00:19:30,970 --> 00:19:32,630 can take between one and 575 00:19:32,920 --> 00:19:34,200 ten AP classes but they 576 00:19:34,650 --> 00:19:35,610 taken at least one to 577 00:19:35,700 --> 00:19:37,490 be an AP student and let's 578 00:19:37,720 --> 00:19:38,970 say that every course has taken 579 00:19:39,350 --> 00:19:40,700 by at least one student and 580 00:19:41,090 --> 00:19:42,270 arbitrary number of students. 581 00:19:43,230 --> 00:19:44,030 So this is one of the 582 00:19:44,120 --> 00:19:46,300 biggest UML diagrams we've seen so far. 583 00:19:46,560 --> 00:19:48,250 Again, this is a superclass up here. 584 00:19:49,380 --> 00:19:51,200 And we have our subclasses down here. 585 00:19:52,360 --> 00:19:53,640 And then we also have an 586 00:19:53,830 --> 00:19:56,490 association, and an association class, and some multiplicities. 587 00:19:56,810 --> 00:19:58,770 And again notice that 588 00:19:58,910 --> 00:20:00,000 is ok that there are 589 00:20:00,160 --> 00:20:01,420 no attributes in the AP 590 00:20:01,680 --> 00:20:03,020 student sub class that sub 591 00:20:03,280 --> 00:20:04,620 classes define as those student 592 00:20:05,020 --> 00:20:06,480 who have taken AP course. 593 00:20:07,160 --> 00:20:08,680 Here are some terminology and properties 594 00:20:09,290 --> 00:20:10,610 associated with sub class relationships, 595 00:20:11,430 --> 00:20:13,200 a super classes and UML 596 00:20:13,610 --> 00:20:15,300 are sometimes called generalization with 597 00:20:15,500 --> 00:20:17,890 sub classes called specialization and 598 00:20:18,030 --> 00:20:19,610 some sub class relationship is said 599 00:20:19,810 --> 00:20:21,340 to be complete if every 600 00:20:21,990 --> 00:20:23,360 object in the super 601 00:20:23,800 --> 00:20:25,010 class is in at least 602 00:20:25,280 --> 00:20:27,520 one sub class and it's 603 00:20:28,420 --> 00:20:29,520 incomplete if that's not 604 00:20:29,900 --> 00:20:31,010 the case and incomplete is also 605 00:20:31,250 --> 00:20:33,210 sometimes known as partial, a 606 00:20:33,290 --> 00:20:34,720 sub class relationship is known 607 00:20:34,990 --> 00:20:37,160 as disjoint if every object 608 00:20:37,550 --> 00:20:40,010 is in at most one subclass. 609 00:20:40,680 --> 00:20:41,550 In other words, we don't have any 610 00:20:41,890 --> 00:20:43,010 objects that are in more than 611 00:20:43,200 --> 00:20:44,890 one subclass, and that's sometimes called exclusive. 612 00:20:46,260 --> 00:20:47,630 And if it's not disjoint, then 613 00:20:47,780 --> 00:20:49,590 it's overlapping, meaning that objects 614 00:20:50,000 --> 00:20:51,160 can be in multiple sub classes. 615 00:20:51,920 --> 00:20:53,720 We can have any combination of these 616 00:20:54,000 --> 00:20:55,070 pairs, so we can have 617 00:20:55,480 --> 00:20:57,080 incomplete overlapping, or incomplete 618 00:20:57,520 --> 00:20:58,990 disjoint, a complete disjoint 619 00:20:59,410 --> 00:21:01,590 that are complete overlapping, lets take 620 00:21:01,750 --> 00:21:02,570 a look back at our example, 621 00:21:04,070 --> 00:21:05,630 for this example we will 622 00:21:05,960 --> 00:21:07,360 probably have the case 623 00:21:07,780 --> 00:21:09,780 that it's a complete subclass relationship. 624 00:21:10,210 --> 00:21:12,070 In other words, every student is 625 00:21:12,210 --> 00:21:13,360 in at least one subclass, 626 00:21:14,090 --> 00:21:15,370 presumably every student is either 627 00:21:15,740 --> 00:21:16,550 a foreign student or a domestic 628 00:21:17,120 --> 00:21:18,820 student and further more, 629 00:21:19,200 --> 00:21:20,570 we're going to say that 630 00:21:20,740 --> 00:21:22,200 it's overlapping because we will 631 00:21:22,430 --> 00:21:23,560 have students who, for example, 632 00:21:24,080 --> 00:21:26,700 are both a domestic student and an AP student. 633 00:21:27,380 --> 00:21:28,540 And in UML, the actual notation 634 00:21:29,070 --> 00:21:30,540 is to put little curly braces here 635 00:21:30,730 --> 00:21:32,100 to specify that that subclass 636 00:21:32,570 --> 00:21:33,750 relationship is complete and overlapping. 637 00:21:35,130 --> 00:21:36,240 To illustrate some of the 638 00:21:36,410 --> 00:21:37,890 other cases, let's suppose that 639 00:21:38,000 --> 00:21:40,500 we didn't have this whole section here with the AP students. 640 00:21:40,960 --> 00:21:42,080 We only had foreign and domestic students. 641 00:21:42,790 --> 00:21:44,040 In that case, we would say 642 00:21:44,330 --> 00:21:46,010 that the subclass relationship is complete. 643 00:21:46,780 --> 00:21:48,040 But in that case it would not be overlapping. 644 00:21:48,660 --> 00:21:49,060 It would be disjoint. 645 00:21:50,670 --> 00:21:51,770 Or suppose we didn't have this 646 00:21:51,920 --> 00:21:52,980 whole left side here so all 647 00:21:53,200 --> 00:21:54,710 we had was the AP student subclass. 648 00:21:55,610 --> 00:21:56,640 In that case, it would 649 00:21:56,860 --> 00:21:57,990 probably be an incomplete complete 650 00:21:58,310 --> 00:22:00,180 subclass relationship because not everybody 651 00:22:00,730 --> 00:22:02,580 is an AP student and 652 00:22:02,790 --> 00:22:03,780 they wouldn't make any difference between 653 00:22:04,080 --> 00:22:05,470 overlapping and disjoints since there 654 00:22:05,600 --> 00:22:07,300 would be only one subclass in that case. 655 00:22:08,390 --> 00:22:09,280 Okay we've now made it to 656 00:22:09,380 --> 00:22:12,140 our last concept which is composition and aggregation. 657 00:22:13,740 --> 00:22:15,090 Let me start by clarifying right off 658 00:22:15,380 --> 00:22:16,870 that aggregation here has nothing 659 00:22:17,400 --> 00:22:18,820 to do with aggregation in SQL. 660 00:22:19,010 --> 00:22:20,080 Well, it's a completely different concept. 661 00:22:20,930 --> 00:22:22,050 So let's first talk about composition. 662 00:22:23,440 --> 00:22:24,650 Composition is used when we 663 00:22:24,750 --> 00:22:26,130 have a database structure where 664 00:22:26,470 --> 00:22:27,850 objects of one class kind 665 00:22:28,110 --> 00:22:29,210 of belong to the objects 666 00:22:29,750 --> 00:22:31,140 of another class and the 667 00:22:31,440 --> 00:22:33,080 example I am going to use is colleges and departments. 668 00:22:34,540 --> 00:22:36,100 So I've drawn the two classes here. 669 00:22:36,610 --> 00:22:37,420 And let's say for the department 670 00:22:38,090 --> 00:22:40,060 we have the department name and 671 00:22:40,460 --> 00:22:42,590 we have say the building that the department is in. 672 00:22:42,670 --> 00:22:43,910 And so we're assuming that 673 00:22:44,280 --> 00:22:45,140 each college has a whole bunch 674 00:22:45,360 --> 00:22:47,390 of departments, now we can 675 00:22:47,550 --> 00:22:48,900 make a relationship, an association 676 00:22:49,620 --> 00:22:51,010 between colleges and departments to 677 00:22:51,120 --> 00:22:52,450 say that the department is in 678 00:22:52,620 --> 00:22:54,060 a college but when we 679 00:22:54,240 --> 00:22:56,550 have the idea that the 680 00:22:56,950 --> 00:22:58,520 departments belong to a 681 00:22:58,960 --> 00:23:00,690 specific college then that's 682 00:23:01,020 --> 00:23:02,670 when this composition construct is used. 683 00:23:03,330 --> 00:23:04,550 And the way the composition is written 684 00:23:04,940 --> 00:23:07,530 is by putting a diamond over 685 00:23:07,920 --> 00:23:09,880 here on the end of the association. 686 00:23:10,500 --> 00:23:12,340 So composition is really a special type association. 687 00:23:13,670 --> 00:23:16,210 And we'll fill in that diamond here to indicate composition. 688 00:23:16,880 --> 00:23:18,450 Aggregation happens to have 689 00:23:18,530 --> 00:23:19,600 an empty diamond which we'll see in 690 00:23:19,700 --> 00:23:21,180 a moment so when 691 00:23:21,360 --> 00:23:22,770 we have the diamond and 692 00:23:22,970 --> 00:23:24,110 we're creating one of 693 00:23:24,190 --> 00:23:25,690 these composition relationships there's 694 00:23:25,750 --> 00:23:27,280 implicitly a one dot 695 00:23:27,480 --> 00:23:28,430 dot one on the left side 696 00:23:28,960 --> 00:23:30,570 so each department belongs to 697 00:23:30,670 --> 00:23:32,270 one college but what's 698 00:23:32,650 --> 00:23:34,170 kind of interesting here, what's 699 00:23:34,550 --> 00:23:35,910 little different from the 700 00:23:36,040 --> 00:23:37,810 normal relationship is that 701 00:23:38,060 --> 00:23:39,380 we're not assuming that this 702 00:23:39,530 --> 00:23:41,190 department name is a primary key exactly. 703 00:23:41,730 --> 00:23:43,280 We could have this same department, in 704 00:23:43,530 --> 00:23:44,580 fact even in the same building, 705 00:23:45,540 --> 00:23:47,870 in different colleges and that 706 00:23:47,960 --> 00:23:48,920 would be okay because a department 707 00:23:49,560 --> 00:23:52,280 is through this relationship associated with it's college. 708 00:23:53,770 --> 00:23:55,310 So that was composition, objects of 709 00:23:55,380 --> 00:23:56,950 one class belonging to objects of another. 710 00:23:57,550 --> 00:23:58,810 Let me give an example of aggregation. 711 00:23:59,490 --> 00:24:00,800 This is a slight stretch but 712 00:24:01,010 --> 00:24:03,010 what I'm going to make is a class of apartments. 713 00:24:03,860 --> 00:24:04,910 Not departments but apartments. 714 00:24:05,720 --> 00:24:06,710 So we're going to imagine that 715 00:24:06,960 --> 00:24:08,650 there are apartment buildings 716 00:24:08,690 --> 00:24:10,420 represented in our database, maybe 717 00:24:10,660 --> 00:24:11,820 they have an address that the primary 718 00:24:12,260 --> 00:24:13,250 key and something like the number 719 00:24:13,620 --> 00:24:15,470 of units, and what we're 720 00:24:15,580 --> 00:24:16,600 going to imagine is that 721 00:24:17,020 --> 00:24:18,630 some apartment buildings are owned 722 00:24:19,030 --> 00:24:20,370 by or associated with the 723 00:24:20,430 --> 00:24:22,220 college but not all of them are. 724 00:24:22,850 --> 00:24:24,410 And that's what aggregation does. 725 00:24:24,690 --> 00:24:25,940 So for aggragation we again 726 00:24:26,320 --> 00:24:28,230 have a relationship here, but 727 00:24:28,370 --> 00:24:29,560 in this case, we make a 728 00:24:29,600 --> 00:24:30,690 diamond on this side that 729 00:24:30,950 --> 00:24:32,480 is open, and what that 730 00:24:32,880 --> 00:24:34,310 says is that each apartment, 731 00:24:35,440 --> 00:24:36,650 each object in the apartment 732 00:24:36,900 --> 00:24:38,930 class is belonging to 733 00:24:39,200 --> 00:24:40,600 a college either at 734 00:24:40,730 --> 00:24:42,520 most one college or no college at all. 735 00:24:43,040 --> 00:24:44,400 So we can have apartments that belong 736 00:24:44,640 --> 00:24:45,380 to a college we can have, 737 00:24:45,650 --> 00:24:47,730 kind of, free-floating apartments and that's 738 00:24:47,910 --> 00:24:50,820 what the open diamond, which is aggregation, is about. 739 00:24:52,340 --> 00:24:53,780 So in conclusion, the data 740 00:24:54,230 --> 00:24:55,620 modeling portion of the 741 00:24:55,690 --> 00:24:57,200 Unified Modeling Language can be 742 00:24:57,500 --> 00:25:00,430 used to perform database design at a higher level. 743 00:25:01,200 --> 00:25:02,090 It's a graphical language. 744 00:25:02,940 --> 00:25:03,980 We went through the five main 745 00:25:04,550 --> 00:25:07,100 concepts of the language, and also 746 00:25:07,360 --> 00:25:09,750 very importantly UML designs can 747 00:25:09,830 --> 00:25:11,410 be translated to relations automatically. 748 00:25:12,320 --> 00:25:14,070 And that is the topic of the next video.