Introduction / Object Orientation 2: Relationships
Subtitles of the Movie
Relationships in object orientation. Objects don't exist in isolation, they exist in relationship to other objects. An example where you can see that very clearly is in this picture of a living room. The living room furniture is contained inside the living room itself, that's one relationship. The pieces of furniture exist in relation to the other pieces of furniture in the room, that's another relationship. And then also each piece of furniture has a conceptual relationship to the kind of furniture that it is. For example the coffee table is a kind of table. Now that is a kind of relationship is an example of a generalization. In generalization the child class is based on the parent class. So here we have a parent class of fish and we have two child classes, goldfish and shark. Now each of those child classes inherits the attributes and operations of the parent class. So whatever defines the fish in terms of it's properties and what it can do also defines the goldfish and it also defines the shark. However even though the goldfish and the shark are both kinds of fish they differ enough from each other in terms of size, shape, ways of eating that each one is it's own class. So you should use a generalization relationship to indicate that two classes, goldfish and shark are similar, they're both fish but they have some differences from each other. Another kind of relationship is association and all that means is that two classes are connected that is related in some way. For example when you plug your speakers into your Cd player you've created an association between your speakers and the CD player and there are several different kinds of association that you might want to take into account. One indicates linkage; information about one class is linked to data about the other class. An example of that is information about a payroll object is associated or linked to data about an employee object. Another kind of association indicates collaboration, one class works with another class to perform some task or you might thing about how one class acts upon the other class. For example the shark eats the goldfish. The next kind of relationship is aggregation and aggregation indicates a relationship between a whole and its parts and in the illustration here we see a school of fish, the school is composed of the individual fish and that is an aggregation relationship. Composition is a strong form of aggregation. In this kind of relationship each part may belong to only one whole. Unlike a fish in a school of fish that could swim away and become part of another whole, become part of a different school of fish in composition each part belongs to only one whole. Think for example of your own living room, that living room is part of your house, its not part of your neighbors house, its not part of anybody else's house, it can't be shared with another house. So we have in composition something we call the no sharing rule, apart in a composition relationship may not belong to any other whole. And what that means is in a composition relationship when the whole is destroyed its parts are destroyed as well and you can see it from the illustration here how that works. When a building is destroyed the rooms that compose it are also destroyed. And one other concept to think about in terms of relationships is multiplicity, multiplicity shows the number of objects that can participate in a relationship. So it shows the number of objects that may be associated with each other in a particular relationship. And if you think about schools, here are some examples. One class occupies one classroom, that's a one to one relationship. One teacher teaches many classes, that's a one to many relationship. What about a many to many relationship. The way to think about that to keep it clear is two one to many relationships. For example one teacher teaches many students and one student learns from many teachers. And that helps you keep things clearer if you think of a many to many relationship in those terms.
Tutorial Information
| Course: | UML |
| Author: | Nancy Conner |
| SKU: | 33815 |
| ISBN: | 1-934743-23-2 |
| Release Date: | 2007-10-26 |
| Duration: | 7 hrs / 95 lessons |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 