среда, 19 декабря 2012 г.
The class s operations are documented in the third (lowest) compartment of the class diagram s recta
This is the next installment in a series of articles cruise the amazon river about the essential diagrams used within cruise the amazon river the Unified Modeling Language, or UML. In my previous article cruise the amazon river on sequence diagrams , I shifted focus away from the UML 1.4 spec to OMG s Adopted 2.0 Draft Specification of UML (a.k.a. UML 2). In this article, I will discuss Structure Diagrams, which is a new diagram category that has been introduced in UML 2. Because the purpose of this series is to educate people about the notation elements and their meanings, this article focuses mainly on the class diagram. The reason for this will soon become clear. Subsequent articles will cover other diagrams included in the structure category.
I also want to remind readers that this series is about UML notation elements, and that these articles are not meant to provide guidance on the best approach for modeling, or how to determine cruise the amazon river what things should be modeled in the first place. Instead, the purpose of this article and of the series in general is to help with a basic understanding of notation elements — their syntax and their meanings. With this knowledge you should be able to read diagrams and create your own diagrams using the proper notation elements.
This article assumes you have a rudimentary understanding of object-oriented design. For those of you who need a little assistance with OO concepts, you might try the Sun brief tutorial Object-Oriented Programming Concepts . Reading the sections What Is a Class? cruise the amazon river and What Is Inheritance? should give you enough understanding to make this article cruise the amazon river useful. cruise the amazon river In addition, David Taylor cruise the amazon river s book, Object-Oriented Technologies: A Manager s Guide , offers an excellent, high-level explanation of object-oriented design without requiring an in-depth understanding of computer programming.
In UML 2 there are two basic categories of diagrams: structure diagrams and behavior diagrams. Every UML diagram belongs to one these two diagram categories. The purpose of structure diagrams is to show the static structure of the system being modeled. They include the class, component, and or object diagrams. Behavioral diagrams, on the other hand, show the dynamic behavior between the objects in the system, including things like their methods, collaborations, and activities. Example behavior diagrams are activity, use case, and sequence diagrams.
As I have said, structure diagrams show the static structure of the system being modeled. focusing on the elements cruise the amazon river of a system, irrespective cruise the amazon river of time. Static structure is conveyed by showing the types and their instances in the system. Besides showing system types and their instances, structure diagrams also show at least some of the relationships among and between these elements and potentially even show their internal structure.
Structure diagrams are useful throughout the software lifecycle for a variety of team members. In general, these diagrams allow for design validation and design communication between individuals and teams. For example, business analysts can use class or object diagrams to model a business s current assets and resources, such as account ledgers, products, or geographic hierarchy. Architects can use the component and deployment diagrams to test/verify that their design is sound. Developers can use class diagrams to design and document the system s coded (or soon-to-be-coded) classes.
UML 2 considers structure diagrams as a classification; there is no diagram itself called a Structure Diagram. However, the class diagram offers a prime example of the structure diagram type, and provides us with an initial set of notation cruise the amazon river elements that all other structure diagrams use. And because the class diagram is so foundational, the remainder of this article will focus on the class diagram s notation set. By the end of this article you should have an understanding of how to draw a UML 2 class diagram and have a solid footing for understanding other structure diagrams when we cover them in later articles.
UML uses a special name for these types: classifiers. Generally, you can think of a classifier as a class, but technically a classifier is a more general cruise the amazon river term that refers to the other three types above as well.
The UML representation of a class is a rectangle containing three compartments stacked vertically, as shown in Figure 1. The top compartment shows the class s name. The middle compartment lists the class s attributes. The bottom compartment lists the class s operations. When drawing a class element on a class diagram, you must use the top compartment, and the bottom two compartments are optional. (The bottom two would be unnecessary on a diagram depicting a higher level of detail in which the purpose is to show only the relationship between the classifiers.) Figure 1 shows an airline flight modeled as a UML class. As we can see, the name is Flight , and in the middle compartment we see that the Flight class has three attributes: flightNumber, departureTime, and flightDuration. In the bottom compartment we see that the Flight class has two operations: delayFlight and getArrivalTime.
The attribute section of a class (the middle compartment) lists each of the class s attributes on a separate line. The attribute section is optional, but when used it contains each attribute of the class displayed in a list format. The line uses the following format:
In business class diagrams, the attribute types usually correspond to units that make sense to the likely readers of the diagram (i.e., minutes, dollars, etc.). However, a class diagram that will be used to generate cruise the amazon river code needs classes whose attribute types are limited to the types provided by the programming language, or types included in the model that will also be implemented in the system.
cruise the amazon river Sometimes it is useful to show on a class diagram that a particular attribute has a default value. (For example, in a banking account application a new bank account would start off with a zero balance.) The UML specification allows for the identification of default values in the attribute list section by using the following notation:
The class s operations are documented in the third (lowest) compartment of the class diagram s rectangle, which again is optional. Like the attributes, the operations of a class are displayed in a list format, with each operation on its own line. Operations are documented using the following notation:
Figure 3 shows that the delayFlight operation has one input parameter — numberOfMinutes — of the type Minutes. However, the delayFlight operation does not have a return value. [Note: The delayFlight does not have a return value because I made a design decision not to have one. One could argue that the delay operation should return the new arrival time, and if this were the case, the operation signature would appear as delayFlight(numberOfMinutes : Minutes) : Date. ] When an operation has parameters, they are put inside the operation s parentheses; each parameter uses the format parameter name : parameter type .
When documenting cruise the amazon river an operation s parameters, you may use an optional indicator to show whether or not the parameter is input to, or output from, the operation. This optional indicator appears as an in or out as shown in the operations compartment in Figure 3. Typically, these indicators are unnecessary unless cruise the amazon river an older programming language such as Fortran will be used, in which case this information can be helpful. However, in C++ and Java, all parameters are in parameters and since in is the parameter s default type according to the UML specification, most people will leave out the input/output indicators.
cruise the amazon river A very important concept in object-oriented design, inheritance , refers to the ability of one class (child class) to inherit the identical functionality of another class (super class), and then add new functionality of its own. (In a very non-technical sense, imagine cruise the amazon river that I inherited my mother s general musical abilities, cruise the amazon river but in my family I m the only one who plays electric guitar.) To model inheritance on a class diagram, a solid line is drawn from the child class (the class inheriting the behavior) with a closed, unfilled cruise the amazon river arrowhead (or triangle) pointing to the super class. Consider types of bank accounts: Figure 4 shows how both CheckingAccount and SavingsAccount classes inherit from the BankAccount class.
In Figure 4, the inheritance relationship is drawn with separate lines for each subclass, which is the method used in IBM Rational Rose and IBM Rational XDE. However, there is an alternative way to draw inheritance called tree notation . You can use tree notation when there are two or more child classes, as in Figure 4, except that the inheritance lines merge together like a tree branch. Figure 5 is a redrawing of the same inheritance shown in Figure 4, but this time using tree notation.
The observant reader will notice that the diagrams in Figures 4 and 5 use italicized cruise the amazon river text for the BankAccount class name and withdrawal operation. This indicates that the BankAccount class is an abstract class and the withdrawal method is an abstract operation. In other words, the BankAccount class provides the abstract operation signature of withdrawal and the two child classes cruise the amazon river of CheckingAccount and SavingsAccount each implement their own version of that operation.
When you model a system, certain objects will be related to each other, and these relationships themselves need to be modeled for clarity. There are five types of associations. I will discuss two of them — bi-directional and uni-directional associations — in this section, and I will discuss the remaining three association types in the Beyond the basics section. Please note that a detailed discussion of when to use each type of association is beyond the scope of this article. Instead, I will focus on the purpose of each association type and show how the association is drawn on a class diagram.
An association is a linkage between two classes. Associations are always assumed
Подписаться на:
Комментарии к сообщению (Atom)
Комментариев нет:
Отправить комментарий